CSI247: DATA STRUCTURES Cover sheet (2023/24) Lab 8 NB: You are allowed to bring ONLY the following to the lab: this year’s lecture notes and the prescribed textbook for reference. Name : ID Date : _________________ : Session (Circle): R9- R11- Declaration: I declare that this piece of assessment is all my own work. I also declare that no part of this assessment has been copied from any source nor have I allowed my work to be copied by Question 1: Question 2: another person. / 15 / 45 Total: Signature: ___________________________ ACADEMIC DISHONESTY Harms the good reputation of our University Affects your personal integrity Is a barrier to the acquisition of the knowledge, skills and attitudes you would have acquired at the end of your study Decreases your value in the eyes of employers Has a heavy penalty including expulsion from UB Lab Objectives – At the end of this lab you should be able to: DO NOT CHEAT OR CONDONE CHEATING BY OTHERS • Draw memory diagrams for a linkedlist • Implement and manipulate LinkedList of String objects / 60 1. Dry Run [15] Suppose you have a linked list with these String objects: [“Thuto”,”Thabo”,”Peo”,”Kamoso”,”Melodi”] Draw memory diagram to represent the linked list and its representations through the following operations: (i) Add name “Keletso” as the second object in the linked list. (ii) Delete first name from the linked list. (iii) Delete all occurrences of names starting with ‘T’ from the linked list. (iv) Delete last name from the linked list. 2. Class StLinkedList: [30] Create a class called StLinkedList with an inner class StNode that implements a LinkedList class of String objects and the different methods to manipulate these objects. The class must have the following instance variables: head for tracking the first node, tail for tracking the last node and size for the number of nodes in the link. Implement the following methods in StLinkedList: a) Default constructor. b) listSize which returns the number of nodes in the linked list. c) insertFirst to insert a node into the linked list at the first position. d) insertLast to insert a node into the linked list at the last position. e) retrieveFirst to retrieve and return first node from a given list them. f) update to update a node at a given location on a list by a given value. g) removeFirst to retrieve and remove first node from a given list them. h) removeNode to remove a node at a given position in the linked list. i) displayAll to display all nodes in the linked list using an enhanced for loop. 3. Class UBApplications: [15] Create an application tester class called UBapplications that uses StLinkedList class above and its methods to create and manipulate a list of strings representing UB admission application numbers. Read 5 application numbers from the keyboard and add them to the list. (Hint: test with 00234adm, 3345cdt, 8675ads, 3459klm, 6568ach). Using the most appropriate methods from StLinkedList class write code to achieve the following operations: a) Append application 5387okf to the end of the linked list. b) Insert application 9021akl after the second application in the linked list. c) Insert application 4421kjt at the front of the linked list. d) Remove application 3345cdt from the linked list. e) Remove the first application from the linked list. f) Remove and return the first application of the linked list. g) Display all applications in the linked list. h) Print the total number of applications in the linked list together with an appropriate text message. Bonus Question: Change the StLinkedList class and implement it is as a generic linked list named GLinkedList. Modify the tester class as well to accommodate generic objects.