Please write a c++ header file, class implementation file and main file that does all of the following and meets the requirements listed below. Also include a Output of your code as to show that your program works and functions properly.
EXERCISING A DOUBLY-LINKED LIST CLASS
This project consists of two parts, the second of which appears below. For the first part, write a class that implements an unordered list abstract data type using a doubly-linked list with pointers to both its first and last nodes. The second part of the project specifies a client program that uses the class.
DESCRIPTION
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, as in this figure:
In the class that implements the list ADT as a doubly-linked list, include two data members: a pointer to the first 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 last character. -> aabbcc#ddee##fg#h aabbcddfh
and another might look like this:
Enter a line of characters; # => delete the last 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);
TESTING
Pay particular attention to verifying that your program works as it should. Plan and describe your tests carefully, and be sure to test novel cases like empty strings, strings that delete more than all their printable characters, and strings that contain no delete characters.
Screenshot of the code:
Sample output:
Code to copy:
#include "stdafx.h" // Include this file if you are using visual studio.
#include <iostream>
#include <cstdlib>
using namespace std;
/*
* Node Declaration
*/
struct node
{
int info;
node *next;
node *prev;
}*head, *tail;
/*
* Class Declaration
*/
class DoublyLinkedList
{
public:
int top1, top2;
void append();
void del();
void display();
DoublyLinkedList()
{
top1 = 0;
top2 = 0;
head = NULL;
tail = NULL;
}
};
/*
* Main: Contains Menu
*/
int main()
{
int choice;
DoublyLinkedList dl;
while (1)
{
cout<<"\n-------------"<<endl;
cout<<"Operations on DoublyLinkedList"<<endl;
cout<<"\n-------------"<<endl;
cout<<"1.append Element into the DoublyLinkedList"<<endl;
cout<<"2.Delete Element from the DoublyLinkedList"<<endl;
cout<<"3.Traverse the DoublyLinkedList"<<endl;
cout<<"4.Quit"<<endl;
cout<<"Enter your Choice: ";
cin>>choice;
cout<<endl;
switch(choice)
{
case 1:
dl.append();
break;
case 2:
dl.del();
break;
case 3:
dl.display();
break;
case 4:
exit(1);
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
}
/*
* append Element in Doubly Ended Queue
*/
void DoublyLinkedList::append()
{
struct node *temp;
int ch, value;
if (top1 + top2 >= 50)
{
cout<<"DoublyLinkedList Overflow"<<endl;
return;
}
if (top1 + top2 == 0)
{
cout<<"Enter the value to be append: ";
cin>>value;
head = new (struct node);
head->info = value;
head->next = NULL;
head->prev = NULL;
tail = head;
top1++;
cout<<"Element append into empty DoublyLinkedList"<<endl;
}
else
{
while (1)
{
cout<<endl;
cout<<"1.append Element at first"<<endl;
cout<<"2.append Element at last"<<endl;
cout<<"3.Exit"<<endl;
cout<<endl;
cout<<"Enter Your Choice: ";
cin>>ch;
cout<<endl;
switch(ch)
{
case 1:
cout<<"Enter the value to be append: ";
cin>>value;
temp = new (struct node);
temp->info = value;
temp->next = head;
temp->prev = NULL;
head->prev = temp;
head = temp;
top1++;
break;
case 2:
cout<<"Enter the value to be append: ";
cin>>value;
temp = new (struct node);
temp->info = value;
temp->next = NULL;
temp->prev = tail;
tail->next = temp;
tail = temp;
top2++;
break;
case 3:
return;
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
}
}
/*
* Delete Element in Doubly Ended Queue
*/
void DoublyLinkedList::del()
{
if (top1 + top2 <= 0)
{
cout<<"DoublyLinkedList Underflow"<<endl;
return;
}
int ch;
while (1)
{
cout<<endl;
cout<<"1.Delete Element at first"<<endl;
cout<<"2.Delete Element at last"<<endl;
cout<<"3.Exit"<<endl;
cout<<endl;
cout<<"Enter Your Choice: ";
cin>>ch;
cout<<endl;
switch(ch)
{
case 1:
head = head->next;
head->prev = NULL;
top1--;
break;
case 2:
tail = tail->prev;
tail->next = NULL;
top2--;
break;
case 3:
return;
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
}
/*
* Display Doubly Ended Queue
*/
void DoublyLinkedList::display()
{
struct node *temp;
int ch;
if (top1 + top2 <= 0)
{
cout<<"DoublyLinkedList Underflow"<<endl;
return;
}
while (1)
{
cout<<endl;
cout<<"1.Display DoublyLinkedList from Beginning"<<endl;
cout<<"2.Display DoublyLinkedList from End"<<endl;
cout<<"3.Exit"<<endl;
cout<<endl;
cout<<"Enter Your Choice: ";
cin>>ch;
cout<<endl;
switch (ch)
{
case 1:
temp = head;
cout<<"DoublyLinkedList from Beginning:"<<endl;
while (temp != NULL)
{
cout<<temp->info<<" ";
temp = temp->next;
}
cout<<endl;
break;
case 2:
cout<<"DoublyLinkedList from End:"<<endl;
temp = tail;
while (temp != NULL)
{
cout<<temp->info<<" ";
temp = temp->prev;
}
temp = tail;
cout<<endl;
break;
case 3:
return;
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
}
Please write a c++ header file, class implementation file and main file that does all of...
C++ program, item.cpp implementation. Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The majority of implementation will be done...
C++ program, inventory.cpp implementation Mostly need the int load(istream&) function. Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The...
This is a c programming problem. Would you please help me to write this problem??? I really appreciate it if you add comments for explanation step by step. Thank you. Reverse a Doubly linked list using recursion: Given a doubly linked list. Reverse it using recursion. Original Doubly linked list: next pointer - DDHIHI Null prev painter Reversed Doubly linked list: next pointer Start Pointer Null prev pointer Include: a) A struct for a node of the doubly linked list....
C++ ONLY PLEASE. CAN I GET SOME HELP WRITING THIS HEADER FILE? I MAINLY WANT TO KNOW HOW I WOULD WRITE IT WITH A TEMPLATE. PLEASE AND THANKS IN ADVANCE. **************LinkedList.h requirements************************ linked list Class EXTRA CREDIT OPPORTUNITY: Create the LinkedList class as a template class for 5 extra credit points!!! private memebers Create a structure called ListNode, which should hold a Dinosaur and a pointer to the next ListNode ListNode pointer called head – will eventually point to the...
Write a C++implementation of a doubly linked list class using a template class representation for a node and using pointers.In its public API provide functions to insert,find, delete, get size and get position of an element. Write C++ code to show those functions work as expected. (MUST COMPILE AND RUN)
C++ Create a class that implements a sorted, doubly-linked list: Start with a copy of the sortedList class. Call your new class doublyLinkedList. Convert the baseline code into a doubly linkedlist, and thoroughly test all existing operations (make sure to check all edge conditions), and then implement the new operations below. The class should have the following additional class methods: • A reverse method: this method will reverse the order of the doubly linked list. This method takes no parameters,...
Please help me on all the questions !!!!!!!! Really need help! Will give a thumb up for helping. True/False (13) Chapter 14 - A List Implementation that Links Data Adding a node to an empty chain is the same as adding a node to the beginning of a chain. Adding a node at the end of a chain of n nodes is the same as adding a node at position n. You need a temporary variable to reference nodes as...
Are based on the following Queue class code segment class QueueFull {/* Empty exception class */}; Class Queue Empty {/* Empty exception class */}; struct Node//Node structure int data;//Holds an integer Node* next;//Pointer to next node in the queue}; Class Queue//Linked node implementation of Queue ADT {Private: Node* front;//Pointer to front node of queue Node* rear;//pointer to last node of queue Public: Queue ()://default constructor initializes queue to be empty -Queue ();//Deallocates all nodes in the queue Void Add (int...
I need this in C++. This is all one question Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...