SlideShare a Scribd company logo
Objective: The purpose of this exercise is to create a Linked List data structure that mimics the
behavior of the Java Standard Library Version (Java API). The outcomes/results of using the
library features should be identical with your own version (My API). However, the underlying
implementation should follow with the descriptions listed below.
Instructions : Create the following Linked List Data Structure with the given description below
in your utils package and use "for loops" for your repetitive tasks.
Where to find starter code in my-api
package.class : utils.LinkedList
package.class : tests.console.week04.LinkedListTest
Where to find your JUNIT test in my-api
package.class : tests.junit.LinkedListJUnitTest
Nested Class that has to be added to LinkedList class
package.class : utils.LinkedList.Node
Task Check List
ONLY "for" loops should be used within the data structure class. There is an automatic 30%
deduction, if other loops are used.
The names of identifiers MUST match the names listed in the description below. Deductions
otherwise.
Complete coding Assignment in your "my-api" GitHub Repository. You will not be graded
otherwise and will receive a 0, if not uploaded there.
Run JUNIT TEST and take a SNAPSHOT of results. Upload PDF of snapshot of your JUnitTest
results to Canvas.
Description
The internal structure of the Linked List is a doubly 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.
last is a reference variable for the last 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: The overloaded constructors will initialize 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.
methods: methods that manages the behavior of the linked nodes.
Together, the methods below give the illusion of a index or countable location. Implement these
methods within your generic Linked List class.
Method
Description
Header
public boolean add(E item)
public void add(int index, E item)
public void append( E item)
private void checkIndex(int index)
public boolean contains(E item)
public void clear()
private E detach(int index)
public E get(int index)
public int indexOf(E item)
private void insertBefore(int index, E item)
public boolean isEmpty()
private Node node(int index)
public E remove(int index)
public boolean remove(E item)
public E set(int index, E item)
public int size()
public String toString()
Node Data Structure
The generic Linked List class includes a static Node class as a nested class, i.e. a static inner
class within the Linked List class.
inner class: class inside the body of another class.
Note: This private class does not require access to instance members of the outer class, so it is
declared static. This means that the node object wont be coupled to the outer class object, thus
will be more optimal since it wont require heap/stack memory.
data fields:
data : hold the data stored in each node as is of type E.
next : stores the location of the next node in the list.
prev : stores the location of the previous node in the list.
constructor:
A constructor that receives parameters for data, and prev and calls the second constructor.
public Node(Node prev, E data)
A constructor that receives parameters for data, next and prev.
public Node(Node prev, E data, Node next)
Method
Description
Header add(item)uses the append method and ensures that there is enough spaces to store each
element in the list. Also updates the number of elements in the list by one. This method returns
true, if the data was added successfully.
public boolean add(E item) add(index, item)inserts elements at a given location in the list,
shifting subsequent elements to the right. Uses the append and insertBefore methods to assist
with adding items to the front, back and middle of the list. Updates the number of elements in the
list by one.
public void add(int index, E item) append(item)appends elements to the end of the list, but does
not update the number of elements. This is a private helper method.
public void append( E item) checkIndex(index)checks if the given index is valid. Validation
means that you cannot access indexes where elements have not been placed. Throws an
IndexOutOfBoundsException, if invalid. This is a private helper method.
private void checkIndex(int index) contains(item)searches for a specific item within the linked
structure and returns true, if the item is in the list.
public boolean contains(E item) clear()clears list of all elements, returns size back to zero.
public void clear() detach(index)detaches the node at the specified index from list and returns
the deleted element, but does not reduce the size of the list. This is a private helper method.
private E 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 E get(int index) indexOf(item)searches for a specific item within the linked structure and
returns the first occurrence (i.e. index location) in the list, otherwise returns -1, if NOT found.
public int indexOf(E item) insertBefore(index, item)inserts an item before the non-null node at
the specified index in the list. Traverses the list to find this node. This method also checks for
insertions at the start and end of the list, as well as when empty. This is a private helper method.
private void insertBefore(int index, E 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 node traverses the list in two directions from front to middle and back to middle. This is
a private helper method.
private Node node(int index) remove(index)removes the item at the given position in the list for
a valid index. Checks for valid index before it proceeds with removal. Shifts subsequent
elements to the left and returns the item removed. The number of elements in the list is reduced
by one.
public E remove(int index) remove(item)removes the first occurrence of the specified item from
the list, if present. Shifts subsequent elements to the left and returns true, if the item is removed.
The number of elements in the list is reduced by one.
public boolean remove(E item) 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 E set(int index, E item)size()returns the number of elements in the list.
public int size()toString()displays the contents of the list according to the same format at shown
in the Java API.
public String toString()

More Related Content

PDF
Objective The purpose of this exercise is to create a Linke.pdf
PDF
Objective The purpose of this exercise is to create a Linke.pdf
PDF
Linked List Objective The purpose of this exercise is to cr.pdf
DOCX
Lecture 18Dynamic Data Structures and Generics (II).docx
PPT
Data structures
PDF
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
PPT
10-linked-list.ppt
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
Linked List Objective The purpose of this exercise is to cr.pdf
Lecture 18Dynamic Data Structures and Generics (II).docx
Data structures
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
10-linked-list.ppt

Similar to Objective The purpose of this exercise is to create a Linked List d.pdf (20)

PDF
please i need help Im writing a program to test the merge sort alg.pdf
PDF
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
PDF
public class MyLinkedListltE extends ComparableltEgtg.pdf
PDF
Implementation The starter code includes List.java. You should not c.pdf
PDF
210 Linked-llists of data structure with .pdf
PDF
STAGE 2 The Methods 65 points Implement all the methods t.pdf
PPT
singly link list project in dsa.....by rohit malav
PPTX
القوائم المترابطة Linked List باستخدام لغة جافا
PDF
In this assignment you will implement insert() method for a singly l.pdf
PDF
Given below is the completed implementation of MyLinkedList class. O.pdf
PPT
DOCX
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
PDF
linklisr
PPT
1 list datastructures
PDF
Note             Given Code modified as required and required met.pdf
PDF
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
DOCX
Please complete all the code as per instructions in Java programming.docx
PPT
Jhtp5 20 Datastructures
PPT
03_LinkedLists_introduction part in details
PPT
03_LinkedLists_091.ppt
please i need help Im writing a program to test the merge sort alg.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
Implementation The starter code includes List.java. You should not c.pdf
210 Linked-llists of data structure with .pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
singly link list project in dsa.....by rohit malav
القوائم المترابطة Linked List باستخدام لغة جافا
In this assignment you will implement insert() method for a singly l.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
linklisr
1 list datastructures
Note             Given Code modified as required and required met.pdf
Lab02kdfshdfgajhdfgajhdfgajhdfgjhadgfasjhdgfjhasdgfjh.pdf
Please complete all the code as per instructions in Java programming.docx
Jhtp5 20 Datastructures
03_LinkedLists_introduction part in details
03_LinkedLists_091.ppt
Ad

More from aliracreations (20)

PDF
One unit of A is made of three units of B, one unit of C, and two un.pdf
PDF
One of the methods that astronomer use to detect the presence of pla.pdf
PDF
One of the important uses of portfolio management tools isa. to .pdf
PDF
One common result of phospholipid signaling pathways downstream of G.pdf
PDF
Once you have completed your Exploratory research you have decided t.pdf
PDF
Once you have your list, respond to the followingList the current.pdf
PDF
One day, Alex got tired of climbing in a gym and decided to take a v.pdf
PDF
On November 1, 2021 a company sign a $200,000.12 percent six-month n.pdf
PDF
On January 1, Year 2, Kincaid Companys Accounts Receivable and the .pdf
PDF
On January 1, 2021, Daniel Corp. acquired 80 of the voting common s.pdf
PDF
On December 31, Year 3, Mueller Corp. acquired 80 of the outstandin.pdf
PDF
No plagiarism. At least 250 wordsWhat is the relationship be.pdf
PDF
On August 1, 2024, Trico Technologies, an aeronautic electronics com.pdf
PDF
On April 1, Mathis purchased merchandise on account from Reece with .pdf
PDF
On 1 January 2021, Alpha Ltd sold inventory to Beta Ltd for $90 000..pdf
PDF
New York State, county, city, school district, and other government .pdf
PDF
nsan davranlar �almasnda, �rg�tsel liderler insanlarn deerleri, tutu.pdf
PDF
nsan adaptasyonu genetik, geliimsel, iklimlendirme ve k�lt�rel olmak.pdf
PDF
Nurse is performing a vaginal exan on a patient who is in labor .pdf
PDF
Nowadays, due to the sophistication of adversarial attack vectors, t.pdf
One unit of A is made of three units of B, one unit of C, and two un.pdf
One of the methods that astronomer use to detect the presence of pla.pdf
One of the important uses of portfolio management tools isa. to .pdf
One common result of phospholipid signaling pathways downstream of G.pdf
Once you have completed your Exploratory research you have decided t.pdf
Once you have your list, respond to the followingList the current.pdf
One day, Alex got tired of climbing in a gym and decided to take a v.pdf
On November 1, 2021 a company sign a $200,000.12 percent six-month n.pdf
On January 1, Year 2, Kincaid Companys Accounts Receivable and the .pdf
On January 1, 2021, Daniel Corp. acquired 80 of the voting common s.pdf
On December 31, Year 3, Mueller Corp. acquired 80 of the outstandin.pdf
No plagiarism. At least 250 wordsWhat is the relationship be.pdf
On August 1, 2024, Trico Technologies, an aeronautic electronics com.pdf
On April 1, Mathis purchased merchandise on account from Reece with .pdf
On 1 January 2021, Alpha Ltd sold inventory to Beta Ltd for $90 000..pdf
New York State, county, city, school district, and other government .pdf
nsan davranlar �almasnda, �rg�tsel liderler insanlarn deerleri, tutu.pdf
nsan adaptasyonu genetik, geliimsel, iklimlendirme ve k�lt�rel olmak.pdf
Nurse is performing a vaginal exan on a patient who is in labor .pdf
Nowadays, due to the sophistication of adversarial attack vectors, t.pdf
Ad

Recently uploaded (20)

PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Types and Its function , kingdom of life
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
GDM (1) (1).pptx small presentation for students
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
master seminar digital applications in india
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
VCE English Exam - Section C Student Revision Booklet
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Types and Its function , kingdom of life
human mycosis Human fungal infections are called human mycosis..pptx
GDM (1) (1).pptx small presentation for students
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Anesthesia in Laparoscopic Surgery in India
master seminar digital applications in india
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Final Presentation General Medicine 03-08-2024.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Pharma ospi slides which help in ospi learning
102 student loan defaulters named and shamed – Is someone you know on the list?
Pharmacology of Heart Failure /Pharmacotherapy of CHF
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
O5-L3 Freight Transport Ops (International) V1.pdf
01-Introduction-to-Information-Management.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

Objective The purpose of this exercise is to create a Linked List d.pdf

  • 1. Objective: The purpose of this exercise is to create a Linked List data structure that mimics the behavior of the Java Standard Library Version (Java API). The outcomes/results of using the library features should be identical with your own version (My API). However, the underlying implementation should follow with the descriptions listed below. Instructions : Create the following Linked List Data Structure with the given description below in your utils package and use "for loops" for your repetitive tasks. Where to find starter code in my-api package.class : utils.LinkedList package.class : tests.console.week04.LinkedListTest Where to find your JUNIT test in my-api package.class : tests.junit.LinkedListJUnitTest Nested Class that has to be added to LinkedList class package.class : utils.LinkedList.Node Task Check List ONLY "for" loops should be used within the data structure class. There is an automatic 30% deduction, if other loops are used. The names of identifiers MUST match the names listed in the description below. Deductions otherwise. Complete coding Assignment in your "my-api" GitHub Repository. You will not be graded otherwise and will receive a 0, if not uploaded there. Run JUNIT TEST and take a SNAPSHOT of results. Upload PDF of snapshot of your JUnitTest results to Canvas. Description The internal structure of the Linked List is a doubly 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. last is a reference variable for the last 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
  • 2. current size of the list without having to traversing the list. constructors: The overloaded constructors will initialize 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. methods: methods that manages the behavior of the linked nodes. Together, the methods below give the illusion of a index or countable location. Implement these methods within your generic Linked List class. Method Description Header public boolean add(E item) public void add(int index, E item) public void append( E item) private void checkIndex(int index) public boolean contains(E item) public void clear() private E detach(int index) public E get(int index) public int indexOf(E item) private void insertBefore(int index, E item) public boolean isEmpty() private Node node(int index) public E remove(int index) public boolean remove(E item) public E set(int index, E item) public int size() public String toString() Node Data Structure The generic Linked List class includes a static Node class as a nested class, i.e. a static inner class within the Linked List class. inner class: class inside the body of another class. Note: This private class does not require access to instance members of the outer class, so it is declared static. This means that the node object wont be coupled to the outer class object, thus will be more optimal since it wont require heap/stack memory.
  • 3. data fields: data : hold the data stored in each node as is of type E. next : stores the location of the next node in the list. prev : stores the location of the previous node in the list. constructor: A constructor that receives parameters for data, and prev and calls the second constructor. public Node(Node prev, E data) A constructor that receives parameters for data, next and prev. public Node(Node prev, E data, Node next) Method Description Header add(item)uses the append method and ensures that there is enough spaces to store each element in the list. Also updates the number of elements in the list by one. This method returns true, if the data was added successfully. public boolean add(E item) add(index, item)inserts elements at a given location in the list, shifting subsequent elements to the right. Uses the append and insertBefore methods to assist with adding items to the front, back and middle of the list. Updates the number of elements in the list by one. public void add(int index, E item) append(item)appends elements to the end of the list, but does not update the number of elements. This is a private helper method. public void append( E item) checkIndex(index)checks if the given index is valid. Validation means that you cannot access indexes where elements have not been placed. Throws an IndexOutOfBoundsException, if invalid. This is a private helper method. private void checkIndex(int index) contains(item)searches for a specific item within the linked structure and returns true, if the item is in the list. public boolean contains(E item) clear()clears list of all elements, returns size back to zero. public void clear() detach(index)detaches the node at the specified index from list and returns the deleted element, but does not reduce the size of the list. This is a private helper method. private E 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 E get(int index) indexOf(item)searches for a specific item within the linked structure and returns the first occurrence (i.e. index location) in the list, otherwise returns -1, if NOT found. public int indexOf(E item) insertBefore(index, item)inserts an item before the non-null node at the specified index in the list. Traverses the list to find this node. This method also checks for insertions at the start and end of the list, as well as when empty. This is a private helper method.
  • 4. private void insertBefore(int index, E 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 node traverses the list in two directions from front to middle and back to middle. This is a private helper method. private Node node(int index) remove(index)removes the item at the given position in the list for a valid index. Checks for valid index before it proceeds with removal. Shifts subsequent elements to the left and returns the item removed. The number of elements in the list is reduced by one. public E remove(int index) remove(item)removes the first occurrence of the specified item from the list, if present. Shifts subsequent elements to the left and returns true, if the item is removed. The number of elements in the list is reduced by one. public boolean remove(E item) 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 E set(int index, E item)size()returns the number of elements in the list. public int size()toString()displays the contents of the list according to the same format at shown in the Java API. public String toString()