Convert a singly-linked lists to a doubly-linked lists

Assignment Help Programming Languages
Reference no: EM131321285

Lab: Ordered DoublyLinked List

Objectives:

To introduce the doubly linked list data structure.

Converting an implementation of singly-linked lists to an implementation of doubly-linked lists.

Strengthen the students understanding of the implementation and use of linked lists.

Background:

A doubly linked list is a variants of linked list structures with additional links that allows for a more efficient insertion or removal of elements from any position in the sequence. Each node contains, besides the next-node link, a second link field pointing to the previous node in the sequence. The two links may be called forward(s) and backwards, or next and prev(ious).

Example:

The following figure shows a doubly linked list whose nodes contain three fields: an integer value, the link forward to the next node, and the link backward to the previous node

Common Mistakes:

Forgetting to change all the links/references when adding or deleting an element.

Lab Exercise:

Implement the following classes:

Class Course that includes four instance variables:

private int ID; // course ID
private String Name; // course name
private Course next; // link next
private Course prev; // link previous

Your class should have the following:

A constructor that initializes the two instance variablesidandname.

Set and get methods for each instance variable.

class Department that includes three instance variables:

private String deptName;
private Course head, tail;

Your class should have the following:

a constructor that initializes the department name
public boolean exist(int id)that checks whether the course object with id passed as parameter exists in the list or not.

Public Boolean insert(int id, String n)that creates and adds the course if the course with id passed as parameter does not exist in the list.

The course must be added in ascending order. The method will return false if the id was a duplicate.

Public Boolean remove(int id)that deletes a course if it exists in the list and return true. The method will return false if the id was not found in the list.

Public String findCourse(int id) that returns a course name if the id exists in the list.

Public void print()that prints the department name and all the courses in the linked list in ascending order.

public void printReverse()that prints the department name and all the courses in the linked list in descending order.

Write a test application named LabTest. In themainmethod, do the following:

Input the department name then create a department object.

Display a menu to the user and 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)

Reference no: EM131321285

Questions Cloud

What is the magnification : A camera is equipped with a lens with a focal length of 36 cm. When an object 2.9 m (290 cm) away is being photographed, what is the magnification?
Write a java program to demonstrate the use of an arraylist : Write a Java program (non-GUI preferred) to demonstrate the use of an ArrayList. The program should allow a user to do the following: Add, edit, delete different types of animals.
What are the allowable limits of deception : Explain why deception is used in behavioral research, and then express your personal feelings about the use of deception. Should deception ever be used? If not, why not? If so, what are the allowable limits of deception?
Calculate the amount of loan you will need : Have a huge impact on who you marry. Are you going to take on another person's debt or are they going to take on your debt and have a huge impact on if/when you buy a house
Convert a singly-linked lists to a doubly-linked lists : Converting an implementation of singly-linked lists to an implementation of doubly-linked lists. Strengthen the students understanding of the implementation and use of linked lists.
How much value does the use of debt add : Under the MM extension with growth, what is the value of your firm's tax shield, i.e., how much value does the use of debt add?
What is lowest density detectable using current transient : At what temperatures would you use these two methods to get maximum sensitivity and sufficiently slow decay to allow the use of highly sensitive but slow capacitance and current meters.?
Initial angular acceleration of the object : 1) What is the initial angular acceleration of the object? 2) What is the initial acceleration  of the center of mass of the object?
Are the reverse characteristics affected : What can you conclude from this exercise - what can an experimental I-V curve reveal about the processing and design difficulties?

Reviews

Write a Review

Programming Languages Questions & Answers

  Develop computerized pot hole tracking and repair system

Department of public works for city has decided to develop computerized pot hole tracking and repair system. As pot holes are reported to customer service.

  Program to use next character to create and return operator

Convert the string of digits into an integer. Otherwise, use the next character to create and return an operator.

  Design and implement program catches and handles exception

Design and implement a program that creates an exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it.

  Write program that computes loan payments

Write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets the user enter the interest rate.

  Create modular program to enter monthly costs expenses

Create the modular program which asks user to enter monthly costs for following expenses incurred from operating his or her automobile: loan payment, tires.

  Design the logic for application for company

Design logic for an application for company which wants a report containing a breakdown of payroll by department. Input includes each employee's last name, first name, department number.

  Write a program which defines an integer array of size

Write a program which defines an integer array of size three (3), the size of the array should be a constant variable. Read data using loops for this array from the user. The data of this array will be the number of vacation days of an employee in..

  Write program using array of seven long integers

Write down the program which uses the following arrays: empId: array of seven long integers to hold employee identification numbers. Array must be initialized with following numbers.

  Write pseudocode to find number of currency denominations

The atm machine gives amount in following denominations 100,500,100 only. Write down pseudocode that will take the amount and write out the number of currency denominations required.

  Track of position of a point in three-dimensional space

Specify, implement and design a class that can be used to keep track of position of a point in three-dimensional space. For example consider the point drawn at the topof the next coloumn. The point shown there has three coordinates

  Write a script to declares and sets variable

Write a script that declares and sets a variable thats equal to the total outstanding balance due. If that balance due is greater than $10,000.00.

  Draw a flow chart to outline how you want to solve

Those cards should be revealed for the remainder of the game - you are required to draw a flow chart to outline how you want to solve this problem.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd