IntList Lab Specifications You are required to come up with
IntList Lab Specifications
You are required to come up with a single header file (IntList.h) that declares and implements the IntNode class (just copy it exactly as it is below) as well as declares the IntList Class interface only. You are also required to come up with a separate implementation file (IntList.cpp) that implements the member functions of the IntList class. While developing your IntList class you must write your own test harness (within a file named main.cpp). Never implement more than 1 or 2 member functions without fulling testing them with your own test harness.
IntNode struct
I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined inline (within the class declaration). Do not write any other functions for the IntNode class. Use as is.
IntList class
Encapsulated (Private) Data Fields
head: IntNode *
tail: IntNode *
Public Interface (Public Member Functions)
IntList(): Initializes an empty list.
~IntList(): Deallocates all remaining dynamically allocated memory (all remaining IntNodes).
void display() const: Displays to a single line all of the int values stored in the list, each separated by a space. This function does NOT output a newline or space at the end.
void push_front(int value): Inserts a data value (within a new node) at the front end of the list.
void pop_front(): Removes the value (actually removes the node that contains the value) at the front end of the list. Does nothing if the list is already empty.
bool empty() const: Returns true if the list does not store any data values (does not have any nodes), otherwise returns false.
IntList(const IntList &cpy): the copy constructor. Make sure this performs deep copy.
IntList & operator=(const IntList &rhs): the overloaded assignment operator. Make sure this performs deep copy.
void push_back(int value): Inserts a data value (within a new node) at the back end of the list.
void clear(): Removes (deallocates) all IntNodes in the IntList. Don\'t forget to set both head and tail to appropriate values for an empty list.
void selection_sort(): Sorts the integers in the list into ascending order. Do NOT move the nodes, just the integers.
void insert_ordered(int value): Inserts a data value (within a new node) in an ordered list. Assumes the list is already sorted in ascending order (i.e., Do not sort the list first, assume the list is already is sorted.) This function loops through the list until if finds the correct position for the new data value and then inserts the new IntNode in that location. This function may NOT ever sort the list.
void remove_duplicates(): Removes all duplicate data values (actually removes the nodes that contain the values) within the list. Always remove just the later value within the list when a duplicate is found. This function may NOT ever sort the list.
friend ostream & operator<<(ostream &out, const IntList &rhs): A global friend function that outputs to the stream all of the integer values within the list on a single line, each separated by a space. This function does NOT send to the stream a newline or space at the end.
main.cpp test harness for PROGRAM
Use this main.cpp file for testing your IntList.
Solution
Your structure for IntNode (struct IntNode) itself is wrong to implement a doubly linked list. There is no previos element in the structure. Without that it is not possible to implement a doubly linked list. With your structure of IntNode it is only possible to create a Singly Linked List.
The following program may help you and you can keep it as a reference in case if you want to change your structure of IntNode. It is my implementation of Doubly Linked list in c++. Use it as a reference.
DList.h:
#ifndef DLIST_H_
#define DLIST_H_
class Node
{
public:
Node *parent;
int data;
Node(int x);
int GetData();
Node *child;
};
class DList
{
public:
Node *head;
Node *tail;
DList();
DList(const DList & );
void PushFront(int a);
void PushEnd(int a);
Node *PopFront();
Node *PopEnd();
void PrintListForward();
void PrintListReverse();
};
#endif
DList.cpp:
#include<iostream>
using namespace std;
#include \"DList.h\"
Node::Node(int x)
{
parent=NULL;
data=x;
child=NULL;
}
int Node::GetData() { return data;}
DList::DList()
{
head=tail=NULL;
}
DList::DList(const DList &dl)
{
Node *newNode=new Node(dl.head->data);
head=newNode;
tail=newNode;
Node *tmp=head,*tmp2=head;
Node *n=dl.head->child;
while(n!=NULL)
{
tmp->child=new Node(n->data);
tmp->child->parent=tmp;
tmp=tmp->child;
tail=tmp;
n=n->child;
}
}
void DList::PushFront(int a)
{
Node *tmp=new Node(a);
if(head==NULL&&tail ==NULL){
head=tail=tmp;
}
else{
tmp->parent=NULL;
head->parent=tmp;
tmp->child=head;
head=tmp;
}
}
void DList::PushEnd(int a)
{
Node *tmp = new Node(a);
if(head==NULL&&tail ==NULL){
head=tail=tmp;
}
else{
tmp->child=NULL;
tmp->parent=tail;
tail->child=tmp;
tail=tmp;
}
}
Node * DList::PopFront()
{
Node *tmp=head;
if(head==NULL)
return NULL;
head=head->child;
if(head!=NULL)
head->parent=NULL;
if(head==NULL)
tail=NULL;
//tmp->child=NULL;
return tmp;
}
Node * DList::PopEnd()
{
Node *tmp=tail;
if(tail==NULL)
return NULL;
tail=tail->parent;
if(tail!=NULL)
tail->child=NULL;
if(tail==NULL)
head=NULL;
tmp->parent=NULL;
return tmp;
}
void DList::PrintListForward()
{
Node *tmp=head;
while(tmp!=NULL)
{
cout<<tmp->data<<\" \";
tmp=tmp->child;
}
cout<<endl;
}
void DList::PrintListReverse()
{
Node *tmp=tail;
while(tmp!=NULL)
{
cout<<tmp->data<<\" \";
tmp=tmp->parent;
}
cout<<endl;
}



