Question: Data Structure In the previous lab, we have created the Department class and the Course class along with their attributes and methods. We have implemented

Data Structure

In the previous lab, we have created the Department class and the Course class along with their attributes and methods. We have implemented the above mentioned using singly linked lists.

In this lab, you should implement the same using doubly linked list

Write the printBackwards() method to print from the tail to the head of the doubly linked list by using the previous.

Then, write a test application named Lab8Test. In the main function, do the following:

  • Create a department object.
  • Input the number of courses in the department.
  • Input the id and name of each course and add it to the department (Hint: Use a loop).
  • Print the courses forward.
  • Input the id of a course to be deleted. Delete the course.
  • Print number of courses.
  • Print the courses backward.

The following lines are the singly linked list requirements.

1. Class Course that includes two instance variables:

int id; // the course ID

String name; // the course name

Course next;

Default and overloaded constructors

2. Class Department that includes two instance variables:

Course head;

Course Tail;

Your class should have the following:

A method that initializes the instance variables.

boolean exist(int) that checks whether the course object with id passed as parameter exists in the singly linked list or not.

void addCourse(int, String) creates and adds the course if the course with id passed as parameter does not exist in the singly linked list.

void deleteCourse(int) to delete a course if it exists in the singly linked list.

void printCourses() prints all the courses in the single linked list.

int countCourses() counts the number of courses in the list.

Java

Please don't take screenshot, write the code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!