Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python ADT Double Linked Dequeue, please read the instructions, I\'ve asked this

ID: 3846108 • Letter: P

Question

Python ADT Double Linked Dequeue, please read the instructions, I've asked this question 8 times now and I haven't gotten the correct answer..

START WITH THIS CODE: https://paste.ee/p/0Q7xz

only add code to the ADT methods where indicated in the code. The file contains extra methods and code at the end to both test your implementation and help you debug your code by using the dump() method. Read the comments in the file. You should keep the names of things the same for everything already defined. (also you can add a instance variable to keep track of the number of nodes in deque, but do not name it size or it will conflict with the instance method named size().)

Your code is test with a series of assert statements. If an assert statement fails, the rest of the testing will not be reached. So fix the problems that cause the first error, before worrying about the next test.

When a test fails, you can either set debug to true at the top of file to dump a graphic picture of the list. or add dq.dump() just before the failing assertion statement.

The test code also calls dq.integrity_check() that verifies that the links look consistent for a double linked List. I follows the links from front and from rear to see if they are not messed up.

Implement the ADT for Deque methods shown in the book using a double linked list to hold the data for the deque.

For Extra Credit:

Also implement a pop method that takes an integer argument i such that it returns the ith nodes data counting from 0 from the beginning of the list if i is positive and returns the ith node counting backward from the end of the list if i is negative. (So pop(-1) would remove and return the last item in the list)

It should also remove the node from the list.

Explanation / Answer

#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class node
{
public:
int data;
class node *next;
class node *prev;
};
class dqueue: public node
{
node *head,*tail;
int top1,top2;
public:
dqueue()
{
top1=0;
top2=0;
head=NULL;
tail=NULL;
}
void push(int x)
{
node *temp;
int ch;
if(top1+top2 >=5)
{
cout <<"dqueue overflow";
return ;
}
if( top1+top2 == 0)
{
head = new node;
head->data=x;
head->next=NULL;
head->prev=NULL;
tail=head;
top1++;
}
else
{
cout <<" Add element 1.FIRST 2.LAST Enter Your Choice:";
cin >> ch;
if(ch==1)
{
top1++;
temp=new node;
temp->data=x;
temp->next=head;
temp->prev=NULL;
head->prev=temp;
head=temp;
}
else
{
top2++;
temp=new node;
temp->data=x;
temp->next=NULL;
temp->prev=tail;
tail->next=temp;
tail=temp;
}
}
}
void pop()
{
int ch;
cout <<"Delete 1.First Node 2.Last Node Enter Your Choice:";
cin >>ch;
if(top1 + top2 <=0)
{
cout <<" Dqueue under flow";
return;
}
if(ch==1)
{
head=head->next;
head->prev=NULL;
top1--;
}
else
{
top2--;
tail=tail->prev;
tail->next=NULL;
}
}
void display()
{
int ch;
node *temp;
cout <<"Display From 1.STARTING 2.ENDING Enter Your Choice";
cin >>ch;
if(top1+top2 <=0)
{
cout <<"under flow";
return ;
}
if (ch==1)
{
temp=head;
while(temp!=NULL)
{
cout << temp->data <<" ";
temp=temp->next;
}
}
else
{
temp=tail;
while( temp!=NULL)
{
cout <<temp->data << " ";
temp=temp->prev;
}
}
}
}