Answer to Question #265442 in C++ for zain

Question #265442

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.


1
Expert's answer
2021-11-13T23:53:28-0500
#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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS