Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Assignment: Linked List In this problem you are going to implement a single linked list of students. A linked list is composed of nodes. So

image text in transcribedimage text in transcribedimage text in transcribed

Assignment: Linked List In this problem you are going to implement a single linked list of students. A linked list is composed of nodes. So first of all, you need a StudentNode class. Each student node should hold his name and ID. In addition to that, each node must hold a pointer or reference to the next node in the list, because this is a linked list and not a simple array The StudentList would hold only a reference to the first node in the list, also known as the head. From this node, we can start traversing the list of students by following the next pointers in each student node. The list also has the following methods: . isEmpty(): returns true if the list does not have any node .addFirst(): adds a new StudentNode to the start of the list. .addLast(): adds a new StudentNode to the end of the list. . print(): print the list by calling toString() for each node getID(): given the name of a student, search in the list, and return his/her ID. . removeNode(): given the name of a student, search in the list, and remove it. . removeAll(): delete all nodes from the list. . reverse: reverse the whole list order by making the first node become the last and vice versa (and everything in between) StudentNode StudentList head: StudentNode name String - ID int next: StudentNode StudentList () +isEmpty (): boolean +addFirst (node StudentNode) +addLast (node: StudentNode) + print () void +getlD (name String): int +removeNode (name String) boolean + removeAll () +reverse () + StudentNode (name String, ID int) // setters & getters +toString) String Write a tester class in which you initialize a StudentList object. Read 4 student names and IDs from the scanner. Add the first one using addLast(), the second one using addFirst(), the third and fourth one using addLast() 1. 2. Print the entire list using print() 3. Call getID("john") and print its result. hold his name and ID. In addition to that, each node must hold a pointer or reference to the next node in the list, because this is a linked list and not a simple array The StudentList would hold only a reference to the first node in the list, also known as the head. From this node, we can start traversing the list of students by following the next pointers in each student node. The list also has the following methods: . isEmpty(): returns true if the list does not have any node . addFirst(): adds a new StudentNode to the start of the list. .addLast(): adds a new StudentNode to the end of the list. . print(): print the list by calling toString() for each node getID(): given the name of a student, search in the list, and return his/her ID. removeNode(): given the name of a student, search in the list, and remove it. removeAll(): delete all nodes from the list. reverse):reverse the whole list order by making the first node become the last and vice versa (and everything in between) . . StudentNode StudentList head: StudentNode name String - ID int - next: StudentNode StudentList () + isEmpty () boolean +addFirst (node StudentNode) +addLast (node: StudentNode) + print () void +getlD (name String): int +removeNode (name String) boolean + removeAll +reverse () + StudentNode (name String, ID // setters & getters +toString() String int) Write a tester class in which you initialize a StudentList object. 1. Read 4 student names and IDs from the scanner. Add the first one using addLast(), the second one using addFirst(), the third and fourth one using addLast() 2. Print the entire list using print() 3. Call getID("john") and print its result. 4. Call removeNode("john'") 5. Print the entire list using print(). 6. Call isEmpty() and print its result. 7. Call removeAll() 8. Call isEmpty() and print its result. Sample Input John 123 Sara 321 Jake 111 Sample Input John 123 Sara 321 Jake 111 Lea 333 Sample Output Sara 321 John 123 Jake 111 Lea 333 John's ID: 123 Sara 321 Jake 111 Lea 333 Empty: false Empty: true

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions