Objective: The purpose of this lab exercise is to create a Singly Linked List data structure . Please note that the underlying implementation should follow with the descriptions listed below.   Instructions : Create the following Linked List Data Structure in your single package and use "for loops" for your repetitive tasks.     Task Check List ONLY "for" loops should be used within the data structure class. Names of identifiers MUST match the names listed in the description below. Deductions otherwise.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Need help with this Java review 

If you can also send a screenshot will be helpful to understan

 

Objective: The purpose of this lab exercise is to create a Singly Linked List data structure . Please note that the underlying implementation should follow with the descriptions listed below.

 

Instructions : Create the following Linked List Data Structure in your single package and use "for loops" for your repetitive tasks.

 

 

Task Check List

  • ONLY "for" loops should be used within the data structure class.
  • Names of identifiers MUST match the names listed in the description below. Deductions otherwise.

 

Description

The internal structure of this Linked List is a singly linked Node data structure and should have at a minimum the following specifications:

data fields: The data fields to declare are private  and you will keep track of the size of the list with the variable size and the start of the list with the reference variable data.

  • first is a reference variable for the first Node in the list.
  • size keeps track of the number of nodes in the list of type int. This will allow you to know the current size of the list without having to traversing the list.

constructors: initializes the data fields size and data.

  • A constructor that is a default constructor initializes the starting node location "first" and size to a zero equivalent, that is, constructs an empty list.

      public SinglyLinkedList()

methods: manages the behavior of the linked nodes.

Together, the methods below give the illusion of an index or countable location. Implement these methods within your generic Linked List class.   

Method

Description

Header

 add(item) uses the append method. This method returns true, if the data was added successfully.

 public boolean add(T item)

 add(index, item) inserts elements at a given location in the list, shifting subsequent elements to the right.

 public void add(int index, T item)

 append(item) appends elements to the end of the list. This is a private helper method.

 public void append(T item)

 checkIndex(index) checks if the given index is valid. Throws an IndexOutOfBoundsException, if invalid. This is a private helper method.

 private void checkIndex(int index)

 detach(index) detaches the node at the specified index from list. This is a private helper method.
 

 private T detach(int index)

 get(index) returns the item at the specified position in the list. This method first checks if the index requested is valid.

 public T get(int index)

 insertBefore(index, item) inserts an item before the non-null node at the specified index in the list. This is a private helper method.
 

 private void insertBefore(int index, T item)

  isEmpty()
 
returns true, if the list is empty, i.e., the list contains no elements.

  public boolean isEmpty()
 

 node(index) returns a reference to the node at the given position in the list. This is a private helper method.
 

 private Node node(int index)

 remove(index) removes the item at the given position in the list. Shifts subsequent elements to the left and returns the item removed.

 public T remove(int index)

 set(index, item) replaces the item at the specified position with the one passed. This method checks if the index requested is valid before it does the replacement and returns the replaced item.

 public T set(int index, T item)

 size()
 
returns the number of elements in the list.

 public int size()

 toString() displays the contents of the list.

public String toString()
 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY