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

17.Given the following class definitions class Deque; class DequeNode friend cla

ID: 3771534 • Letter: 1

Question

17.Given the following class definitions class Deque; class DequeNode friend class Deque; private: int data; DequeNode *prev; DequeNode *next; class Deque private: DequeNode *head; int number; DequeNode *tail; public: Deque ) Deque() void push front (const int &); void push back (const int &) int front () int back ) int pop front ); int pop back ) void printAll ); Write C++ code for the following questions a. Implement the member function push_back (const int &). The function adds a new entry at the back of a deque. The total number of nodes should be increased by one. The deque might be empty (2 Marks) b. Implement the member function pop_back (). The function removes the node at the back of a deque and returns the data of the node. The total number of nodes should be decreased by one. The deque might be empty (2 Marks) Implement the member function back (). The function returns the data value at the back of a deque. The deque might be empty c. (1 Mark)

Explanation / Answer

here the concept is fistly check whether deque had content or not if yes then the top2 is incremented and added the data at that address.

initialize in constructor number1=0 and number2=0;

void deque::push_back(int x)
{
   node *temp;
   int ch;
   if(number1+number2 >=5)
   {
      cout <<"dqueue overflow";
      return ;
   }
   if( number1+number2 == 0)
      {
        head = new node;
        head->data=x;
        head->next=NULL;
        head->prev=NULL;
        tail=head;
        top1++;
      }
   else
   {
         number2++;
         temp=new node;
         temp->data=x;
         temp->next=NULL;
         temp->prev=tail;
         tail->next=temp;
         tail=temp;
       }
}

delete a node first go to that location and assign the next to null and removes the connection

void deque::pop_back()
{
    if(number1 + number2 <=0)
   {
     cout <<" Dqueue under flow";
     return;
   }
else

{ int d=tail->data;
     number2--;
     tail=tail->prev;
     tail->next=NULL;
}

return d;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote