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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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