Program MUST be in C Program MUST be in C Source code for ma

Program MUST be in C++!!!!

Program MUST be in C++!!!!!

//Source code for main.c

In this project you are asked to design and implement a class for double link list to hold integers The class should be called DList, you also need a class called Node that contains an int as the data Node needs the following data: int data; //the data held by the node Node parent; //the parent of the Node Node child the child of the Node Node needs the following public functions Node (int) constructor to create a Node with the input int int GetData return the int held by the Node DList needs a head and tail, both should be pointers to Node, and initialized to NULL DList needs a default constructor (no parameter), a copy constructor (take const DList & as input) DList needs the following public functions: void PushFront (int a //create a Node containing a //and add it to the front of the list void PushEnd (int a //create a Node containing a //and add it to the end of the list No de PopFront //popping out the first Node of the list, //if the list is empty, return NULL Node PopEnd //popping out the last Node of the list, //if the list is empty, return NULL void PrintListForward //print every element from start to end //in one line separated by a space void PrintListReverse //print every element from end to start //in one line separated by a space 2 Files to turn in: You need to turn in four files in a tar.gz file: makefile, main.C DList.C, DList.h. Among them, you need to use the main C provided from the class web site which you cannot modify at all. DList h declares the class DList and Node. You can make DList the friend of Node so it can access the private data of the Node.

Solution


/*
* Node Declaration
*/
using namespace std;
class Node
{
int data;
struct node *parent;
struct node *child;
   public :
   Node(int data){
       this.data = data;
      
   }
   int GetData(){
       return this.data;
   }
  
};

/*
Class DList Declaration
*/
class DList
{
   Node* head;
   Node* tail;
public:
       DList(){
           *head = NULL;
           *tail = NULL;
       }
       DList( const DList& obj){
           *head = *obj.head;
           *tail = *obj.tail;
          
       }
void pushFront(int value);
void pushEnd(int value);
Node* popFront();
Node* popEnd();
void printListForward();
void printListBackward();
  
};


/*
* Insertion at the beginning
*/
void double_llist::pushFront(int value)
{
   Node* newNode = new Node(value);
  
   newNode->parent = NULL;
if (head == NULL)
{
head = newNode;
       newNode->child = NULL;
       tail = head;
      
}else{
       newNode->child = head;
       head = newNode;
      
   }
  
  
}

/*
* Insertion of element at the end position
*/
void double_llist::pushEnd(int value)
{
  
   Node* newNode = new Node(value);
  
if (head == NULL)
{
head = newNode;
       newNode->parent = NULL;
      
}else{
       newNode->parent = tail;
       tail->child = newNode;
      
   }
   newNode->child = NULL;
   tail = newNode;
}

/*
* Deletion of element from the list from front
*/
Node* double_llist::popFront()
{
Node* nodeToReturn = head;
   head = head->child;
   head->parent = NULL;
   nodeToReturn->child = NULL;
   return nodeToReturn;

}
/*
* Delete from last of the list
*/
Node* double_llist::popEnd()
{
Node* nodeToReturn = tail;
   tail = tail->parent;
   tail->child = NULL;
   nodeToReturn->parent = NULL;
   return nodeToReturn;

}

/*
* Display elements of Doubly Link List
*/
void double_llist::printListForward()
{
Node *q;
if (head == NULL)
{
cout<<\"List empty,nothing to display\"<<endl;
return;
}
q = head;
cout<<\"The Doubly Link List is :\"<<endl;
while (q != NULL)
{
cout<<q->data<<\" \";
q = q->child;
}
  
}
/*
* Display elements of Doubly Link List in reverse
*/
void double_llist::printListBackward()
{
Node *q;
if (head == NULL)
{
cout<<\"List empty,nothing to display\"<<endl;
return;
}
q = tail;
cout<<\"The Doubly Link List in reverse is :\"<<endl;
while (q != NULL)
{
cout<<q->data<<\" \";
q = q->parent;
}
  
}

Program MUST be in C++!!!! Program MUST be in C++!!!!! //Source code for main.c In this project you are asked to design and implement a class for double link li
Program MUST be in C++!!!! Program MUST be in C++!!!!! //Source code for main.c In this project you are asked to design and implement a class for double link li
Program MUST be in C++!!!! Program MUST be in C++!!!!! //Source code for main.c In this project you are asked to design and implement a class for double link li

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site