Instructions: Kindly check the code below and (correct if there are mistakes in the program), and must require to put SORTING and SEARCHED. (20 max size value; set it vertical for stacks and horizontal for queue on the display from SORTING.) #include using namespace std; struct Node {     int data; Node *link; }; Node *top = NULL; bool isempty() {     if(top == NULL)     return true;     else     return false; } void push (int value) {     Node *ptr = new Node();     ptr->data = value;     ptr->link = top;     top = ptr; } void pop() {     if (isempty())         cout<<"## Stack is Empty"< link;         delete(ptr);     } } void showTop() {     if (isempty())     cout<<"## Stack is Empty"<data <data;         temp=temp->link;         counter++;     }     cout<<"## Stack Size : "<dataQ= valueQ;  ptr->linkQ = NULL;  if( front == NULL )  {   front = ptr;   rear = ptr;  }  else  {   rear ->linkQ = ptr;   rear = ptr;  } } void dequeue ( ) {  if( isemptyQ() )  cout<<"Queue is empty\n";  else  if( front == rear)  {   free(front);   front = rear = NULL;  }  else  {   NodeQ *ptr = front;   front = front->linkQ;   free(ptr);  } } void showfront( ) {  if( isemptyQ())  cout<<"Queue is empty\n";  else  cout<<"Element at front is: "<dataQ; } void sizeQueue() {  if (isemptyQ())   cout<<"Queue is empty\n";  else  {   NodeQ *ptr = front;   int counterQ = 0;   while( ptr !=NULL)   {    ptr->dataQ;    ptr= ptr->linkQ;    counterQ++;   }   cout << "Size is: " << counterQ <> mm; if (mm == 1) {     int choice, flag=1, value, count=0;     const int MAX_SIZE=5;     while( flag == 1)     {         cout<<"\nMENU FOR STACKS: " <>choice;     switch (choice)     {     case 1: if(count==MAX_SIZE){                 cout<<"## Stack is Full!"<>value;             push(value);             count++;             }          break;     case 2: pop();          count--;          break;     case 3: showTop();          break;     case 4: size();          break;     case 5: flag = 0;          break;     default: cout << "\nWrong Choice!!\n";     }  } }  else if (mm == 2)  { int ch, flag2=1, value; while( flag2 == 1) {     cout << "\nMENU FOR QUEUES: "<>ch; switch (ch)   {   case 1: cout<<"Enter Value: ";           cin>>value;           enqueue(value);           break;   case 2: dequeue();           break;   case 3: showfront();           break;   case 4: sizeQueue();           break;   case 5: flag2 = 0;           break;   }  } } else {     flow=0; } } exit(0); }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Instructions: Kindly check the code below and (correct if there are mistakes in the program), and must require to put SORTING and SEARCHED. (20 max size value; set it vertical for stacks and horizontal for queue on the display from SORTING.)

#include<iostream>

using namespace std;

struct Node
{
    int data;

Node *link;
};

Node *top = NULL;

bool isempty()
{
    if(top == NULL)
    return true;
    else
    return false;
}

void push (int value)
{
    Node *ptr = new Node();
    ptr->data = value;
    ptr->link = top;
    top = ptr;
}

void pop()
{
    if (isempty())
        cout<<"## Stack is Empty"<<endl;
    else
    {
        Node *ptr = top;
        top = top -> link;
        delete(ptr);
    }
}

void showTop()
{
    if (isempty())
    cout<<"## Stack is Empty"<<endl;
    else
    cout<<"The element at top is : "<< top->data <<endl;
}

void size()
{
    if (isempty())
        cout<<"## Stack is Empty"<<endl;
    else
    {
        Node *temp=top;
    int counter = 0;
    while(temp!=NULL)
    {
        temp->data;
        temp=temp->link;
        counter++;
    }
    cout<<"## Stack Size : "<<counter<<endl;
    }
}

struct NodeQ
{
int dataQ;

NodeQ *linkQ;
};

NodeQ *front = NULL;
NodeQ *rear = NULL;

bool isemptyQ()
{
 if(front == NULL && rear == NULL)
 return true;
 else
 return false;
}

void enqueue ( int valueQ )
{
 NodeQ *ptr = new NodeQ();
 ptr->dataQ= valueQ;
 ptr->linkQ = NULL;

 if( front == NULL )
 {
  front = ptr;
  rear = ptr;
 }
 else
 {
  rear ->linkQ = ptr;
  rear = ptr;
 }
}

void dequeue ( )
{
 if( isemptyQ() )
 cout<<"Queue is empty\n";
 else

 if( front == rear)
 {
  free(front);
  front = rear = NULL;
 }
 else
 {
  NodeQ *ptr = front;
  front = front->linkQ;
  free(ptr);
 }
}

void showfront( )
{
 if( isemptyQ())
 cout<<"Queue is empty\n";
 else
 cout<<"Element at front is: "<<front->dataQ;
}

void sizeQueue()
{
 if (isemptyQ())
  cout<<"Queue is empty\n";
 else
 {
  NodeQ *ptr = front;
  int counterQ = 0;
  while( ptr !=NULL)
  {
   ptr->dataQ;
   ptr= ptr->linkQ;
   counterQ++;
  }
  cout << "Size is: " << counterQ <<endl;
 }
}

int main()
{
int flow=1;
while (flow == 1)
{
    int mm;
cout << "\nMain Menu: " <<endl;
cout << "\n[1] Stacks";
cout << "\n[2] Queues";
cout << "\n[3] Quit\n";
cout << "\nEnter Choice: ";
cin >> mm;

if (mm == 1)
{
    int choice, flag=1, value, count=0;
    const int MAX_SIZE=5;

    while( flag == 1)
    {
        cout<<"\nMENU FOR STACKS: " <<endl;
        cout << "\n[1] Push";
        cout << "\n[2] Pop";
        cout << "\n[3] Top";
        cout << "\n[4] Size";
        cout << "\n[5] Exit\n";
        cout<<"\nEnter your choice : ";
        cin>>choice;
    switch (choice)
    {
    case 1: if(count==MAX_SIZE){
                cout<<"## Stack is Full!"<<endl;}
         else{
            cout<<"Enter the Value to be pushed : ";
            cin>>value;
            push(value);
            count++;
            }
         break;
    case 2: pop();
         count--;
         break;
    case 3: showTop();
         break;
    case 4: size();
         break;
    case 5: flag = 0;
         break;
    default: cout << "\nWrong Choice!!\n";
    }
 }
}
 else if (mm == 2)
 {

int ch, flag2=1, value;

while( flag2 == 1)
{
    cout << "\nMENU FOR QUEUES: "<<endl;
    cout << "\n[1] Enqueue";
    cout << "\n[2] Dequeue";
    cout << "\n[3] Front";
    cout << "\n[4] Size";
    cout << "\n[5] Exit\n";
    cout << "\nEnter your choice: ";
    cin>>ch;
switch (ch)
  {
  case 1: cout<<"Enter Value: ";
          cin>>value;
          enqueue(value);
          break;
  case 2: dequeue();
          break;
  case 3: showfront();
          break;
  case 4: sizeQueue();
          break;
  case 5: flag2 = 0;
          break;
  }
 }
}
else
{
    flow=0;
}
}
exit(0);
}

 

Main Menu:
Main Menu:
[1] Stacks
[2] Queues
[3] Quit
[1] Stacks
[2] Queues
[3] Quit
Enter Choice: 1
Enter Choice: 2
MENU FOR STACKS:
MENU FOR QUEUES:
[1] Push
[2] Pop
[3] Top
[4] Size
[5] Sort
[6] Display
[7] Search
[8] Exit
[1] Enqueue
[2] Dequeue
[3] Front
[4] Size
[5] Sort
[6] Display
[7] Search
[8] Exit
Enter your choice :
Enter your choice:
Transcribed Image Text:Main Menu: Main Menu: [1] Stacks [2] Queues [3] Quit [1] Stacks [2] Queues [3] Quit Enter Choice: 1 Enter Choice: 2 MENU FOR STACKS: MENU FOR QUEUES: [1] Push [2] Pop [3] Top [4] Size [5] Sort [6] Display [7] Search [8] Exit [1] Enqueue [2] Dequeue [3] Front [4] Size [5] Sort [6] Display [7] Search [8] Exit Enter your choice : Enter your choice:
Expert Solution
steps

Step by step

Solved in 10 steps with 7 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY