

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This task was assigned by Prof. Chandrashekar Baag at Amrita Vishwa Vidyapeetham. This assignment is related to Data Structures and Representation course. It includes: Choice, Switch, Stack, Push, Case, Break, Pop, Wrong, Enter, Number
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


#include<conio.h> #include<iostream.h> void push (int,int,int); int pop (int,int); void main () { int queue[10],len,top=-1,stack[10],stop=-1,input,popout; char choice='y'; clrscr();
while(choice=='y') { cout<<"\nEnter the number of pages you want to print:\t"; /The person with least number of pages will be given the highest priority / cin>>input; if(top==-1) /For the first entry/ { top=0; queue[0]=input; } if (queue[top]>input) /For entry having less number of pages as compared to the highest number of pages in the queue/ { while(queue[top]>input && top>-1) { popout=pop(&queue[top],&top); /Moves higher number of pages than the current entry to stack such that elements in stack settels in ascending order, from top to bottom/ push(&stack[stop],&stop,popout); top--; } top=top+1; queue[top]=input; /Enters curent entry at its appropriate position/
while(stop>-1) { popout=pop(&stack[stop],&top);stop--; /Pushes back the values from stack into the queue such that they automaticaly settels in ascending order in the queue/ push(&queue[top],&top,popout); } }
if(queue[top]<input) { push(&queue[top],&top,input); /If current value is higher than any entry of the queue/ }
cout<<"\nCurrent Queue-->\n\n\t"; for(int j=0;j<=top;j++) { cout<<queue[j]<<" "; /To Display/
cout<<"\n\n\n\nPress 'y' for new entry, any other to exit:\t"; cin>>choice; } }
void push (int st,int t,int in) { if (t>8 && in>st) { cout<<" "; } else { t=t+1; st++; *st=in;
} }
int pop (int *s,int to) { if(to<0) { cout<<"The stack is empty\n"; } else { return *s; s--; } }