Need help with this Java review    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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Need help with this Java review 

 

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()
 

 

 

can   you please also screen shot cause it helps to understand the code better


 

 

 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education