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

C++ implementation of a static deque class(deque.cpp). create deque.cpp and impl

ID: 3733547 • Letter: C

Question

C++ implementation of a static deque class(deque.cpp).

create deque.cpp and implement it using deque.h

“deque.h” provided below

PROGRAMS:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

deque.h

#ifndef _DEQUE_H_
#define _DEQUE_H_

#include
#include
#include "node2.h"

using namespace main_savitch_6B;

template
class deque
{
public:
typedef std::size_t size_type;

deque();
  
~deque();
  
deque(const deque& dq);
  
deque& operator = (const deque& dq);
  
  
T& front();
  
T front() const;
  
T& back();
  
T back() const;
  
void push_front (const T& entry);
  
void push_back (const T& entry);
  
void pop_front();
  
void pop_back();
  
size_type size() const;
  
bool empty() const;
  
template
friend bool operator == (const deque& dq1, const deque& dq2);

template
friend std::ostream& operator<< (std::ostream& out, const deque& dq);

private:
size_type count; // Total number of items in the queue
node* first;
node* last;
};

#include "deque.template"

#endif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**** node2.h ****

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node2.template

Explanation / Answer

program:

#include <iostream>

#include <cstdlib>

using namespace std;

struct node

{

    int content;

    node *later;

    node *before;

}top, end;

class dqueue

{

    public:

        int top1, top2;

        void push();

        void remove();

        void show();

        dqueue()

        {

            top1 = 0;

            top2 = 0;

            top = NULL;

            end = NULL;

        }

};

int main()

{

    int choice;

    dqueue dl;

    while (1)

    {

    

        cout<<"Operations on Deque"<<endl;

     

        cout<<"1.push Element into the Deque"<<endl;

        cout<<"2.remove Element from the Deque"<<endl;

        cout<<"3.Traverse the Deque"<<endl;

        cout<<"4.Quit"<<endl;

        cout<<"Enter your Choice: ";

        cin>>choice;

        cout<<endl;

        switch(choice)

        {

        case 1:

            dl.push();

            break;

        case 2:

            dl.remove();

            break;

        case 3:

            dl.show();

            break;

        case 4:

            exit(1);

            break;

        default:

            cout<<"Wrong Choice"<<endl;

        }

    }

    return 0;

}

void dqueue::push()

{

    struct node *read;

    int ch, value;

    if (top1 + top2 >= 50)

    {

        cout<<"Dequeue Overflow"<<endl;

        return;

    }

    if (top1 + top2 == 0)

    {

        cout<<"Enter the value to be pushed: ";

        cin>>value;

        top = new (struct node);

        top->content = value;

        top->later = NULL;

        top->before = NULL;

        end = top;

        top1++;

        cout<<"Element pushed into empty deque"<<endl;

    }

    else

    {

        while (1)

        {

            cout<<endl;

            cout<<"1.push Element at first"<<endl;

            cout<<"2.push Element at last"<<endl;

            cout<<"3.Exit"<<endl;

            cout<<endl;

            cout<<"Enter Your Choice: ";

            cin>>ch;

            cout<<endl;

            switch(ch)

            {

            case 1:

                cout<<"Enter the value to be pushed: ";

                cin>>value;

                read = new (struct node);

                read->content = value;

                read->later = top;

                read->before = NULL;

                top->before = read;

                top = read;

                top1++;

                break;

            case 2:

                cout<<"Enter the value to be pushed: ";

                cin>>value;

                read = new (struct node);

                read->content = value;

                read->later = NULL;

                read->before = end;

                end->later = read;

                end = read;

                top2++;

                break;

            case 3:

                return;

                break;

            default:

                cout<<"Wrong Choice"<<endl;

            }

        }

    }

}

void dqueue::remove()

{

    if (top1 + top2 <= 0)

    {

        cout<<"Deque Underflow"<<endl;

        return;

    }

    int ch;

    while (1)

    {

        cout<<endl;

        cout<<"1.delete element at beginning"<<endl;

        cout<<"2.remove element at end "<<endl;

        cout<<"3.Exit"<<endl;

        cout<<endl;

        cout<<"Enter Your Choice: ";

        cin>>ch;

        cout<<endl;

        switch(ch)

        {

        case 1:

            top = top->later;

            top->before = NULL;

            top1--;

            break;

        case 2:

            end = end->before;

            end->later = NULL;

            top2--;

            break;

        case 3:

            return;

            break;

        default:

            cout<<"Wrong Choice"<<endl;

        }

    }

}

void dqueue::show()

{

   struct node *read;

    int ch;

    if (top1 + top2 <= 0)

    {

        cout<<"Deque Underflow"<<endl;

        return;

    }

    while (1)

    {

        cout<<endl;

        cout<<"1.show Deque from Beginning"<<endl;

        cout<<"2.show Deque from End"<<endl;

        cout<<"3.Exit"<<endl;

        cout<<endl;

        cout<<"Enter Your Choice: ";

        cin>>ch;

        cout<<endl;

        switch (ch)

        {

        case 1:

            read = top;

            cout<<"Deque from Beginning:"<<endl;

            while (read != NULL)

            {

                cout<<read->content<<" ";

                read = read->later;                    

            }

            cout<<endl;

            break;

        case 2:

            cout<<"Deque from End:"<<endl;

            read = end;

            while (read != NULL)

            {

                cout<<read->content<<" ";

                read = read->before;                   

            }

            read = end;

            cout<<endl;

            break;

        case 3:

            return;

            break;

        default:

            cout<<"Wrong Choice"<<endl;

        }

    }

}

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