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

Language C++ Write a queue class to implement a queue using a 2 directional link

ID: 3799983 • Letter: L

Question

Language C++

Write a queue class to implement a queue using a 2 directional linked list.

Test the program with the following sequence of code:

queue myQ;   ( Use default constructor to initialize front and end to NULL. )

cout<< myQ.size() << endl; // number of elements in queue

myQ.dequeue();   // Try to deqeue when the queue is empty. Should catch UNDERFLOW

myQ.enqueue("Fred");

myQ.enqueue("Liv");

myQ.enqueue("Julie");

myQ.enqueue("Rich");

myQ.enqueue("William");

myQ.enqueue("Olo");

myQ.enqueue("Xi");

myQ.enqueue("Chu");

myQ.enqueue("Annie");

myQ.enqueue("Carlos");

myQ.enqueue("Tuyet");

myQ.enqueue("Sue");

cout<< myQ.front() << endl; // name at front, if not empty

cout<< myQ.end() << endl;   // name at end, if not empty

cout<< myQ.size() << endl;   // number of elements in queue

cout << myQ.dequeue() << endl;

cout << myQ.dequeue() << endl;

cout << myQ.dequeue() << endl;;

myQ.enqueue("Olive");

myQ.enqueue("Jim");

cout << myQ.dequeue() << endl;

cout << myQ.dequeue() << endl;

cout<< myQ.front() << endl; // name at front, if not empty

cout<< myQ.end() << endl;   // name at end, if not empty

cout<< myQ.size() << endl;   // number of elements in queue

Explanation / Answer

#include&lt;iostream&gt;
#include&lt;cstdio&gt;
#include&lt;cstdlib&gt;
using namespace std;

/*
* Node Declaration
*/
struct node
*start, *last;
int counter = 0;
/*
* category Declaration
*/
class double_clist
begin = NULL;
last = NULL;          
}
};

/*
* Main: Contains Menu
*/
int main()
worker = new(struct node);
temp-&gt;info = value;
temp-&gt;next = NULL;
temp-&gt;prev = NULL;
come back temp;
}
/*
*INSERTS component AT starting
*/
void double_clist::insert_begin()
{
int value;
cout&lt;&lt;endl&lt;&lt;"Enter the component to be inserted: ";
cin&gt;&gt;value;
struct node *temp;
temporary worker = create_node(value);
if (start == last &amp;&amp; begin == NULL)
{
cout&lt;&lt;"Element inserted in empty list"&lt;&lt;endl;
begin = last = temp;
start-&gt;next = last-&gt;next = NULL;
start-&gt;prev = last-&gt;prev = NULL;
}
else
{
temp-&gt;next = start;
start-&gt;prev = temp;
begin = temp;
start-&gt;prev = last;
last-&gt;next = start;
cout&lt;&lt;"Element inserted"&lt;&lt;endl;
}
}

/*
*INSERTS ELEMNET eventually
*/
void double_clist::insert_last()
{
int value;
cout&lt;&lt;endl&lt;&lt;"Enter the component to be inserted: ";
cin&gt;&gt;value;
struct node *temp;
temporary worker = create_node(value);
if (start == last &amp;&amp; begin == NULL)
{
cout&lt;&lt;"Element inserted in empty list"&lt;&lt;endl;
begin = last = temp;
start-&gt;next = last-&gt;next = NULL;
start-&gt;prev = last-&gt;prev = NULL;
}
else
  
}
/*
*INSERTS component AT POSITION
*/
void double_clist::insert_pos()
{
int value, pos, i;
cout&lt;&lt;endl&lt;&lt;"Enter the component to be inserted: ";
cin&gt;&gt;value;
cout&lt;&lt;endl&lt;&lt;"Enter the postion of component inserted: ";
cin&gt;&gt;pos;
struct node *temp, *s, *ptr;
temporary worker = create_node(value);
if (start == last &amp;&amp; begin == NULL)
{
if (pos == 1)
{
begin = last = temp;
start-&gt;next = last-&gt;next = NULL;
start-&gt;prev = last-&gt;prev = NULL;
}
else
  
ptr-&gt;next = s-&gt;next;
s-&gt;next-&gt;prev = ptr;
if (pos == counter)
  
counter--;
free(s);
cout&lt;&lt;"Element Deleted"&lt;&lt;endl;
}
/*
* Update worth of a selected node
*/
void double_clist::update()
{
int value, i, pos;
if (start == last &amp;&amp; begin == NULL)
  
s-&gt;info = value;
cout&lt;&lt;"Node Updated"&lt;&lt;endl;
}
/*
* Search component within the list
*/
void double_clist::search()
zero, value, i;
bool flag = false;
struct node *s;
if (start == last &amp;&amp; begin == NULL)