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

  Your program should read data from a file

Your program should read data from a file which contains one number per line. The total number of lines is not known before execution of the program. The program should detect the end of file to stop reading the data.

  Write function to merge contents of two sorted arrays

Write a function which will merge contents of two sorted (ascending order) arrays of type FLOAT values, use efficient bubble sort to sort two arrays first and then use merger function.

  Create a spreadsheet to calculate the total costs

Create a spreadsheet to calculate the total costs for each item, total cost, and percent of the total used for each item. Be sure to label columns and rows so it is clear what is in your spreadsheet. Also, type in your formulas and use functions..

  Write functions to change and display attributes

Write class player which contains attributes for players name,average and team. Write three functions to change and display these attributes.

  Write a program with three functions upper lower and reverse

Write a program with three functions: upper, lower, and reverse. The upper function will accept a pointer to a string or C-string as an argument. It will step through each character in the string converting it to uppercase.

  Front end applications

How does a compiled binary executable store on the client computer?

  Import the data in excel to the table in access.

There are 6 tables in Access (Contacts, Customer, Orders, Products, SalesRep and Territories) and I also created 6 sheets in Excel for the data for table

  Explain about lexical analyzer

Explain about Lexical Analyzer

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  What is code reuse

What is code reuse. How does inheritance help achieve code reuse

  Determine and print the average age of your family

Design a program that will allow a user to Input a list of your family members along with their age and state where they reside. Determine and print the average age of your family and print the names of anyone who live in Texas

  Create a class named rectangle with length and width

To cover that floor with carpet that costs $8 per square foot would cost $960. (12 x 10 x8 = 960.). You should create a class named Rectangle with the following properties:

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