Lab 3: Ordered Doubly Linked List Objectives: 1. To introduce the doubly linked list data structure. 2. Converting an im
Posted: Fri Jul 08, 2022 6:39 am
Your class should have the following: • a constructor that initializes the department name • exist (id) that checks whether the course object with id passed as parameter exists in the linked list or not. .insert(id, n) that creates and adds the course if the course with id passed as parameter does not exist in the linked list. The course must be added in ascending order. The method will return false if the id was a duplicate. remove (id) that deletes a course if it exists in the linked list and return true. The method will return false if the id was not found in the list. • • findCourse (id) that returns a course name if the id exists in the linked list. • print () that prints the department name and all the courses in the linked list in ascending order. • printReverse() that prints the department name and all the courses in the linked list in descending order. Write the expected time and space complexity as a comment at the beginning of each method of your class. 3. Write a test program named Lab3Test. Do the following: • Input the department name then create a department object. • Display a menu to the user asking for a choice to be entered as follows: The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: • The program will perform the action selected by the user and display a proper message when necessary. • The program will repeat these actions until the user terminates the program (Hint: Use a loop). Sample Output: Please enter the name of the department: Computer Engineering The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 14
5- print courses in reverse 6- exit Please enter your selection: 30 Error! Incorrect choice. The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 4 Computer Engineering department does not have any courses. The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 1 Enter the course number or -1 to stop: 300 Enter the course name: Design and Analysis of Algorithms Enter the course number or -1 to stop: 356 Enter the course name: Computer Networks I Enter the course number or -1 to stop: 300 Enter the course name: testing duplicate Error! duplicate ID number... Enter the course number or -1 to stop: 325 Enter the course name: Human-Computer Interaction Enter the course number or -1 to stop: 262 Enter the course name: Fundamentals of Digital Logic Enter the course number or -1 to stop: -1 The program can perform the following: 1- insert a course 2- remove a course. 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 4 15
Courses in Computer Engineering department are: 1- 262 Fundamentals of Digital Logic 2 3 325 Human-Computer Interaction 4- 356 Computer Networks I 300 Design and Analysis of Algorithms The program can perform the following: 1- insert a course 2- renove a course 3- search for a course 4- print courses 5- print courses in reverse. 6- exit Please enter your selection: 5 Courses in Computer Engineering department printed in reverse are: 1- 356 Computer Networks I 2- 325 Human-Computer Interaction 3 4 262 Fundamentals of Digital Logic The program can perform the following: 1- insert a course 300 Design and Analysis of Algorithms 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 2 Enter the course number: 325 The course was removed The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 2 Enter the course number: 325 The course is not in the list The program can perform the following: 1- insert a course 2- remove a course 3- search for a course 16
4- print courses 5- print courses in reverse 6- exit Please enter your selection: 4 Courses in Computer Engineering department are: 1 - 262 Fundamentals of Digital Logic 2- 300 Design and Analysis of Algorithms 3 356 Computer Networks I The program can perform the following: 1- insert a course 2- renove a course. 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 5 Courses in Computer Engineering department printed in reverse are: 1 356 Computer Networks I 2- 300 Design and Analysis of Algorithms 3 262 Fundamentals of Digital Logic The program can perform the following: 1- insert a course 2- renove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 3 Enter the course number: 300 The id: 300 corresponds to Design and Analysis of Algorithms The program can perform the following: 1- insert a course 2- renove a course. 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 3 Enter the course number: 325 The id: 325 does not correspond to any course in the department The program can perform the following: 1- insert a course 17
2- remove a course 3- search for a course 4- print courses 5- print courses in reverse 6- exit Please enter your selection: 6 Exiting the program...