Question: Write a class that implements an unordered list ADT. This class should provide the following operations: A default constructor that initializes a newly declared list

Write a class that implements an unordered list ADT. This class should provide the following operations:

A default constructor that initializes a newly declared list to be empty.

A destructor that deletes all the nodes in a list.

empty(), a boolean function that reports if the list that invokes it is empty.

append(entry), which appends the item entry at the end of the list.

remove_last(), which removes the last item from the list.

An output function that prints the list in forward order to an output stream; you may assume that "<<" can be used with items of the list.

Implement the unordered-list ADT using a doubly-linked list with pointers to both its first and last nodes

In the class that implements the list ADT as a doubly-linked list, include two data members: a pointer to thefirst node in the list, and a pointer to the last node in the list. Note that the pointer to the list's last node makes both append() and remove_last() fast. Thus the class's data members will be something like this:

 struct Node { Item data; Node *next; Node *back; }; Node *first; Node *last; 

You may want to write a program with which to test this class.

Here's something to do with the unordered-list implementation:

DESCRIPTION

Consider this line-editing problem: A program reads characters one at a time, then prints them back to the terminal in order. However, the character `#' is not to be saved. Rather, it indicates that the program is to delete the most recent character. After reading reaches the end of the line, the surviving characters are printed in forward order. For example:

input: abcd##ef => output: abef

Write a program that uses the unordered-list implementation to solve the editing problem just described. Use a doubly-linked list, provided by the class, to hold the characters of the input line in the order in which they are entered.

INPUT

The program reads characters one at a time. Any number of the characters may be the delete character `#'. You may not use the function get_line().

OUTPUT

The program prints the surviving (non-deleted) characters from the input, in the order in which they appeared.

ERRORS

The program may assume that the input is as described; it need not detect any errors.

EXAMPLE

A run of the program might look like this:

 Enter a line of characters; # => delete the most recent character. -> aabbcc#ddee##fg#h aabbcddfh 

and another might look like this:

 Enter a line of characters; # => delete the most recent character. -> djfg#######abc#def abdef 

HINTS

The Item type in the unordered list class is char.

For the client program, recall that the function get() reads the next character from the named input stream into the function's parameter, which is passed by reference. Example: cin.get(ch);

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!