Write pseudocode for the following Given a stack and a queue
Write pseudocode for the following:
Given a stack and a queue, write a function that calls existing stack/queue functions to check if they contain the same data (top of the stack must be identical to the front of the queue, etc.)
Solution
#include<stdio.h>
 #include<process.h>
 #include<malloc.h>
 int Qarr[50], noq, Front = -1, Rear = -1;
 struct mystack
 {
 int no;
 struct mystack *next;
 }*top = NULL;
 typedef struct mystack st;
//Add dat to stack
 void push( )
 {
 st *p;
 p = (st *) malloc(sizeof(st));
 printf(\"\  Enter the number \");
 scanf(\"%d\", &p -> no);
 p -> next = top;
 top = p;
 }
//Remove data from stack
 int pop( )
 {
 st *p;   p = top;
 if(top == NULL)
     printf(\"\  Stack Underflow\");
 else
 {
     top = top -> next;
 return (p -> no);
 }
 }
//Display data from stack
 void dispS()
 {
 st *p;   p = top;
 while(p != NULL)
 {
    printf(\"\  no = %d\", p -> no);
 p = p -> next;
 }
 }
//Add data to Queue
void Que_Ins( )
 {
 int Item;
 if(Rear < noq-1)
 {
 printf(\"\  Enter a number \");
 scanf(\"%d\", &Item);
 if(Front == -1)
 Front = Rear = 0;
 else
 Rear++;
 Qarr[Rear] = Item;
 }
 else
 {
 printf(\"\  Queue OVERFLOW \ \");
 exit(0);
 }
 }
//Display data from queue
 void dispQ( )
 {
 int c;
 printf(\"\  QUEUE Contents \  \");
 for(c = 0; c < noq; c++)
 printf(\" |Q[%d]| = %3d \", c+1, Qarr[c]);
 }
//Remove data from queue
 int Que_Del( )
 {
 int val;
 if(Front != -1)
 {
 val = Qarr[Front];
 if(Front == Rear)
 Front = Rear = -1;
 else
 Front++;
 printf(\"\  Deleted Item = %d \", val );
 printf(\"Front= %d Rear= %d\", Front, Rear);
 return val;
 }
 else
 printf(\"\  Stack UNDERFLOW \ \");
 }
void main( )
 {
 int c, f = 0, nos, items, itemq;
 printf(\"\  Enter How many Elements need for Stack\");
 scanf(\"%d\",&nos);
 for(c = 0; c < nos; c++)
 push();
 printf(\"\  Enter How many Elements need for Queue\");
 scanf(\"%d\",&noq);
 for(c = 0; c < noq; c++)
 Que_Ins();
 if(nos != noq)
 {
 printf(\"\  Not Identical \");
 }
 dispS();
 dispQ();
 for(c = 0; c < nos; c++)
 {
 items = pop();
 itemq = Que_Del();
 if(items != itemq)
 {
 f = 1;
 break;
 }
 }
 if(f == 1)
 printf(\"\  Not Identical\");
 else
 printf(\"\  Identical\");
 }
Output 1:
Enter How many Elements need for Stack3
Enter the number 10
Enter the number 20
Enter the number 30
Enter How many Elements need for Queue3
Enter a number 30
Enter a number 20
Enter a number 10
no = 30
 no = 20
 no = 10
 QUEUE Contents
 |Q[1]| = 30 |Q[2]| = 20 |Q[3]| = 10
 Deleted Item = 30 Front= 1 Rear= 2
 Deleted Item = 20 Front= 2 Rear= 2
 Deleted Item = 10 Front= -1 Rear= -1
 Identical
Output 2:
Enter How many Elements need for Stack3
Enter the number 10
Enter the number 20
Enter the number 30
Enter How many Elements need for Queue3
Enter a number 30
Enter a number 10
Enter a number 20
no = 30
 no = 20
 no = 10
 QUEUE Contents
 |Q[1]| = 30 |Q[2]| = 10 |Q[3]| = 20
 Deleted Item = 30 Front= 1 Rear= 2
 Deleted Item = 10 Front= 2 Rear= 2
 Not Identical




