Question: Question 140 Marks Given a class diagram for List as in Figure 1. Complete a linked list program given in Program 1. Define List class





Question 140 Marks Given a class diagram for List as in Figure 1. Complete a linked list program given in Program 1. Define List class and write the implementation for all the function members for List to accomplish each of the following tasks: List - head: StudentNode* - tail: StudentNode* : + task1(StudentNode*): void + task2(StudentNode"); void + task3(): void + task4(): void + task5(StudentNode*, int): void + task6(): void Figure 1: List class 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 //Program 1 class Scuder: Node public: string name: -10 CPA StudentNode *next, prev; StudentNode (string r=NC-L, float c=0) 1 Clare CPA = C: next. - NOTT; prev - NUTI; } 1 int main() 16 List Studligt; StudentNode *31 new StudentNode("Lisa", ?.56); studentNode #32 = new StudentNode("Shah", 3.75); Student Node +33 = new StudentNode("Aman", 3.67); slucentNode *34 = new Sluden-Node "Iman", 1.95); StucentNode *35 = new StudentNode("Afic", 3.67); = "", 17 18 19 20 21 22 23 24 25 26 27 28 29 30 cout Shah - 3.75 -> min 3.67] Figure 5: Output after the execution of the statement in Line 28 Task 4: Define a function named task4. The function should able to delete the first node in the list. Figure 6 shows the result of this task after the execution of the statement in Linc 29. (6 marks) prev Fiume CPA nex prev name next Shah 3,75 Anin 3.67 head tail Figure 6: Current nodes in the list after the deletion of the first node in the list Task 5: Define a function named task5. The function should able to insert a new student node at 5a . a the middle of the list. The position of the new node in the list depends on the value of the sccond argument of this function. Assume the value of the second argument of this function is 2. This means that the new node will be the second node in the list (being in 4 the second position in the list). Figure 7 shows the result of this task after the cxccution of the statement in Line 31 and Figure 8 shows the result of this task after the execution of the statement in Line 32. Note: In this task, you should use a loop. (11 marks) prev yaxe CPA next ' Shah 3.75 . pre nowe CPA mert Im: 3.85 pe name CPA next | Amin 3.67 ++ head tail Figure 7: Current nodes in the list after the insertion node at the second position in the list prev w CPA next 2 ve Flame CPA next prev name CP: next nope Iman 3.85 4 prev Hanc CPA next Amin 3.67 Shah 3.75 + Aliq 3.61 head tail Figure 8: Current nodes in the list after the insertion node at the third position in the list Task 6: Define a function named task 6. The function should able to delete the last node in the list. Figure 9 shows the result of this task after the execution of the statement in Line 34. (6 marks) preve CP4 next Shah 3.75 prewe CPA next + Iman 3.85 1 pre rame CP4 next Afiq 3.61 head tail Figure 9: Current nodes in the list after the deletion of the last node in the list 5 After completing all tasks, please make sure your program should be able to produce the output as shown in Figure 10. Print forward: [T 3.56] => [Shah 3.75 -> [Amin 3.67] Print forward: [Shah 3.751 -> Amin 3.67] Print forward: [Shah 3.75] -> [Inan 3.851 -> [Afiq 3,61] -> [Amin 3.67] Print forward: [Shah 3.75] -> [lman 3.851 -> [Afiq 3.61] Figure 8: The output of completed Program 1 6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
