(Lab-8 Manual) CS-204-DSA - Linked List
(Lab-8 Manual) CS-204-DSA - Linked List
Spring 2019
Lab-8 Manual
Linked List
v1.0
5/18/2019
Lab-8 Manual 2019
List
A list provides a way to organize data. We can have to-do lists, gift lists, address lists, grocery
lists, even lists of lists. These lists provide a useful way for us to organize our lives, as illustrated
in Figure given below. Each list has a first item, a last item, and usually items in between.
That is, the items in a list have a position: first, second, and so on. An item’s position might be
important to you, or it might not. When adding an item to your list, you might always add it at
the end, or you might insert it between two other items already in the list.
Page 1
Lab-8 Manual 2019
a convenient way to identify a particular entry is by the entry’s position within the list. It could
be first, that is, at position 1, or second (position 2), and so on. This convention allows you to
describe, or specify, the operations on a list more precisely.
The following is an initial specification of the list:
1. add(newEntry) : Adds a new entry to the end of a list.
2. add(newPosition, newEntry) : Adds a new entry at a given position in a list.
3. remove(givenPosition) : Removes the entry at a given position from a list.
4. clear() : Removes all entries from a list.
5. replace(givenPosition, newEntry) : Replaces the entry at a given position
in a list with a given entry.
6. getEntry(givenPosition) : Retrieves the entry at a given position in a list.
7. contains(anEntry) : Sees whether a list contains a given entry.
8. getSize() : Gets the number of entries in a list.
9. isEmpty(): Sees whether a list is empty.
10. displayList() : Display all values from the list
11. incSize() : To increment the size by 1
12. descSize() : To decrement the size by 1
Page 2
Lab-8 Manual 2019
Note: You may copy these files from the Code folder.
Note: You may use the displayList(ListInterface list) method from the
LListClient.java class provided to you in the code folder.
4. Create a new list IntegerList using the LList class of type Integer.
5. Add 5 new entries in list.
6. Display the list using the displayList method.
7. Add another new entry at position 6.
8. Display the list using the displayList method.
9. Remove an entry at position 2 and then display the list.
10. Replace the value at position 1 with a new entry and display list.
11. Repeat the Same process from point 4 to onwards for the types Double and Character as
well.
Page 3
Lab-8 Manual 2019
Note: You may use the displayList(ListInterface list) method from the
LListClient.java class provided to you in the code folder.
Page 4
Lab-8 Manual 2019
If I wanted to add a new entry it will add at the end, for example if I add a new number 120 my
list will look like
Or I can use the position method, for example I wanted to add a new number 200 at position 2
my list will look like
But I wanted to update the list in the way which add the entry at the beginning that means when I
add a new number 300 my list will look like
I can do it by using the Add at position method, but you are not supposed to use that method but
need to update the our LList class by writing some other methods
addBeginning
updateBeginning
removeBeginning
Page 5
Lab-8 Manual 2019
In order to write these methods in LList first you need to add new methods in the Interface as
well.
Page 6