Task 2.
Create a class Node with
a. attributes data, next and previous pointer
b. accessors and mutators for this class
c. constructor and destructor
d. function called display.
Using the node from task 2, implement a class called DLL with following functionalities
1. insert a node at first ,
2. overload to Insert a node at last
3. overload to Insert at specified position of double linked list. E.g if the position number is 6, it is inserted between node at position 5 and 7. If position number is greater than the size of list, it is prompted that the position number does not exist and therefore is being inserted at end.
#imclude <iostrem>
using namespace std;
class Node{
public:
int exam;
Node *next;
Node *prev;
void display(){
Node *mymk=new Node;
Node *Head=new Node;
Node *p=new Node;
p->exam=20;
p->next=NULL;
Head->next=p;
p->prev=Head;
Node *q=new Node;
p->exam=30;
p->next=Head->next;
Head->next=q;
q->prev=Head;
Node *r=new Node;
p->exam=40;
p->next=Head->next;
Head->next=r;
r->prev=Head;
Node *s=new Node;
s->exam=50;
p->next=Head->next;
Head->next=s;
s->prev=Head;
Node *q=new Node;
p->exam=30;
p->next=Head->next;
Head->next=p;
p->prev=Head;
for(int i=1;i<=5;i++){
Node *t=new Node;
cout<<"Enter the node Exam value"<<endl;
cin>>T->exam;
t->next=Head->next;
Head->next=t;
t->prev=Head;
Node *q=new Node;
q->next=Head;
while(q->next){
q=q->next;}
Node *n=new Node;
n->exam=95;
n->next=NULL;
q->next=n;
n->prev=q;
mymk=Head->next;
while (mymk!=0){
cout<<"Exam value"<<mymk->exam<<endl;
mymk=mymk->next;}
}
};
int main()
{
Node d;
d.display();
}
Comments
Leave a comment