SlideShare a Scribd company logo
Linked List
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<E> in the list.
last is a reference variable for the last Node<E> 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<E> 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<E> prev, E data)
A constructor that receives parameters for data, next and prev.
public Node(Node<E> prev, E data, Node<E> 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<E> 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

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

PPT
List data structure
Mahmoud Abuwarda
 
PPT
List Data Structure
Zidny Nafan
 
PPT
1 list datastructures
Nguync91368
 
PPT
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
PPT
linked list (c#)
swajahatr
 
PPT
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
 
PDF
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
DOCX
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
Komlin1
 
PDF
There are a couple of new methods that you will be writing for this pr.pdf
aamousnowov
 
PPTX
Collection Framework-1.pptx
SarthakSrivastava70
 
PDF
Seo Expert course in Pakistan
ssuserb2c86f
 
PDF
Linked list (java platform se 8 )
charan kumar
 
PDF
DSA Lab Manual C Scheme.pdf
Bharati Vidyapeeth COE, Navi Mumbai
 
PDF
Collections and generics
Muthukumaran Subramanian
 
DOC
Advanced core java
Rajeev Uppala
 
PPTX
Adt of lists
Nivegeetha
 
PDF
Part B- Implementing a Sorted Linked list The class declarations has b.pdf
info571050
 
PPTX
Linked List Representation of a Linked List.pptx
AAUsH2
 
PPT
singly link list project in dsa.....by rohit malav
Rohit malav
 
PPTX
Java.util
Ramakrishna kapa
 
List data structure
Mahmoud Abuwarda
 
List Data Structure
Zidny Nafan
 
1 list datastructures
Nguync91368
 
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
linked list (c#)
swajahatr
 
LINKEDb2bb22bb3b3b3b3n3_LIST_UKL_1-2.ppt
Farhana859326
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
The MyLinkedList class used in Listing 24.6 is a one-way directional .docx
Komlin1
 
There are a couple of new methods that you will be writing for this pr.pdf
aamousnowov
 
Collection Framework-1.pptx
SarthakSrivastava70
 
Seo Expert course in Pakistan
ssuserb2c86f
 
Linked list (java platform se 8 )
charan kumar
 
DSA Lab Manual C Scheme.pdf
Bharati Vidyapeeth COE, Navi Mumbai
 
Collections and generics
Muthukumaran Subramanian
 
Advanced core java
Rajeev Uppala
 
Adt of lists
Nivegeetha
 
Part B- Implementing a Sorted Linked list The class declarations has b.pdf
info571050
 
Linked List Representation of a Linked List.pptx
AAUsH2
 
singly link list project in dsa.....by rohit malav
Rohit malav
 
Java.util
Ramakrishna kapa
 

More from adityacomputers001 (20)

PDF
Lord Esher declar en Willis v Baddeley 1892 2 QB 324 dec.pdf
adityacomputers001
 
PDF
Los equipos pueden fallar debido a las tareas que los miembr.pdf
adityacomputers001
 
PDF
Los efectos de red son Opcin multiple aumentos en el val.pdf
adityacomputers001
 
PDF
Los escarabajos vienen en una amplia variedad de formas hb.pdf
adityacomputers001
 
PDF
Los astrnomos nunca observarn directamente los primeros mi.pdf
adityacomputers001
 
PDF
Los auditores a menudo ganan honorarios considerables de una.pdf
adityacomputers001
 
PDF
Los atajos cognitivos que influyen en la forma en que las pe.pdf
adityacomputers001
 
PDF
Los animales que se clasifican fcilmente en phyla existente.pdf
adityacomputers001
 
PDF
Lophotrochozoans have traits that are present in some but no.pdf
adityacomputers001
 
PDF
Looking at the equation and figure below write a User Defin.pdf
adityacomputers001
 
PDF
Logistics Consultants Inc LCi provides various logistics .pdf
adityacomputers001
 
PDF
logical description of the primary joints up to 2 within .pdf
adityacomputers001
 
PDF
logistic modelFirst order ordinary differential equations .pdf
adityacomputers001
 
PDF
Lincoln and the Global Economy_posted under Week 5 Instruct.pdf
adityacomputers001
 
PDF
Local state and national agencies such as the Center for D.pdf
adityacomputers001
 
PDF
LO 39 Explain the importance of gene expression regulation .pdf
adityacomputers001
 
PDF
LO36 Explain why the genetic code is degenerate Which of the.pdf
adityacomputers001
 
PDF
Lo ms probable es que una empresa que tiene una ________ .pdf
adityacomputers001
 
PDF
Load the German Credit data using the following code import.pdf
adityacomputers001
 
PDF
LO49 Explain how expression of related genes can be coordina.pdf
adityacomputers001
 
Lord Esher declar en Willis v Baddeley 1892 2 QB 324 dec.pdf
adityacomputers001
 
Los equipos pueden fallar debido a las tareas que los miembr.pdf
adityacomputers001
 
Los efectos de red son Opcin multiple aumentos en el val.pdf
adityacomputers001
 
Los escarabajos vienen en una amplia variedad de formas hb.pdf
adityacomputers001
 
Los astrnomos nunca observarn directamente los primeros mi.pdf
adityacomputers001
 
Los auditores a menudo ganan honorarios considerables de una.pdf
adityacomputers001
 
Los atajos cognitivos que influyen en la forma en que las pe.pdf
adityacomputers001
 
Los animales que se clasifican fcilmente en phyla existente.pdf
adityacomputers001
 
Lophotrochozoans have traits that are present in some but no.pdf
adityacomputers001
 
Looking at the equation and figure below write a User Defin.pdf
adityacomputers001
 
Logistics Consultants Inc LCi provides various logistics .pdf
adityacomputers001
 
logical description of the primary joints up to 2 within .pdf
adityacomputers001
 
logistic modelFirst order ordinary differential equations .pdf
adityacomputers001
 
Lincoln and the Global Economy_posted under Week 5 Instruct.pdf
adityacomputers001
 
Local state and national agencies such as the Center for D.pdf
adityacomputers001
 
LO 39 Explain the importance of gene expression regulation .pdf
adityacomputers001
 
LO36 Explain why the genetic code is degenerate Which of the.pdf
adityacomputers001
 
Lo ms probable es que una empresa que tiene una ________ .pdf
adityacomputers001
 
Load the German Credit data using the following code import.pdf
adityacomputers001
 
LO49 Explain how expression of related genes can be coordina.pdf
adityacomputers001
 
Ad

Recently uploaded (20)

PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Ad

Linked List Objective The purpose of this exercise is to cr.pdf

  • 1. Linked List 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<E> in the list. last is a reference variable for the last Node<E> 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)
  • 2. 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<E> 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<E> prev, E data) A constructor that receives parameters for data, next and prev. public Node(Node<E> prev, E data, Node<E> 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)
  • 3. 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)
  • 4. 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<E> 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)
  • 5. 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()