Question: The program needs to be in C++, please include the main function and some comment lines for me to understand better. DNode class that can
The program needs to be in C++, please include the main function and some comment lines for me to understand better.
- DNode class that can store integer data and the address of next and prev DNode.
- Introduce a DLL (Doubly Linked List) class
- Introduce a front private data member
- Introduce a DLL constructor and destructor
- Introduce insertToFront function
- Introduce deleteFromFront function
- Introduce printAll function
- Introduce deleteLast function
- Introduce insertToMiddle function
- Introduce deleteMiddle function
- Introduce deleteLastNode function
- InsertInOrder function: insert a new node so the list reads in ascending order from the beginning to the end.
- removeOneTargetNode(int target) //remove the first target node found in the list
- removeAllTargetNodes(int target)// remove all target node(s) found in the list
- isDuplicate //return true if there is any node that are duplicate in the list. For example, 1->2->3->4 is a unique SLL. However, 1->2->3->2->1 is duplicate since 1 repeats two times and 2 repeats two times.
- Introduce a CLL (Doubly Linked List) class and all the above functions.
This is the layout I have so far, feel free to use this as a reference or you could use any other methods you may think of:
#include
using namespace std;
class DNode
{
//Public Class Data Members
public:
int data; //Stores item
DNode *next; //Moves to next
DNode *prev; //Moves to previous
}
void print(DNode *head, DNode *tail)
{}
class DLL
{
private:
DNode *front;
DNode *back;
public:
//Constructor
DLL()
{
front = NULL;
}
//Destructor
~DLL()
{
delete front;
delete back;
}
int length()
{}
void insertToFront(int data)
{}
void deleteFromFront()
{}
void printAll()
{}
void deleteLast()
{}
void insertToMiddle(int position, int data)
{}
void deleteMiddle(int position)
{}
void InsertInOrder(DNode *head, DNode *tail, int key)
{}
} ;
int main()
{
DNode *head = NULL;
DNode *tail = NULL;
DNode *node1 = new Node(1);
DNode *node2 = new Node(3);
DNode *node3 = new Node(5);
DNode *node4 = new Node(3);
DNode *node5 = new Node(3);
DNode *node6 = new Node(1);
return 1;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
