void F(Queue& Q)
{
int a[64], n=0,i;
int elt;
while(!Q.QEmpty())
a[n++]=Q.QDelete();
<code here>
}
for(i=0;i<n;i++) Q.QInsert(a[i]);
for(i=n-1;i>=0;i--) Q.QInsert(a[i])
void F(int A[], int n)
{
Stack S;
int i;
for(i=0;i<n;i++)
S.Push(A[i]);
i=0;
while(!S.StackEmpty())
A[i++]=S.Pop();
}
void F(int A[], int n)
{
PQueue PQ;
int i;
for(i=0;i<n;i++)
PQ.PQInsert(A[i])
while(!PQ.PQEmpty())
A[--i]=PQ.PQDelete();
}
S.Push(9);
S.Push(x);
S.Push(y);
x=S.Pop();
y=S.Pop();
cout<<y<<endl; //Output 1 _____
S.Push(22);
while(!S.StackEmpty())
{
y=S.Pop();
cout <<y<<endl; //Output 2 ____
}
cout <<x<<endl; //Output 3
Q.QInsert(x);
Q.Qinsert(15)
Q.Qinsert(y);
x=Q.QDelete();
Q.Qinsert(22);
x=Q.Qdelete();
Q.Qinsert(45);
while(!Q.QEmpty())
{
y=Q.QDelete(); //Output 1 _____
cout << y << endl;
}
cout <<x<<endl; //Output 2 ______
typedef int DataType;
#include "astack.h"
void F(Stack& S, Stack &T, int n)
{
int item;
T.ClearStack();
while(!S.StackEmpty())
{
item=S.Pop();
if(item<n)
T.Push(item);
}
}
void main(void)
{
int A[5]={2, 1, 7, 4, 3}, i;
Stack S,T; //Declare two stack objects.
for(i=0;i<5;i++)
S.Push(A[i]);
F(S,T,4); PrintStack(T);
}
1 2 3 4 LILO FILO FIFO LIFO
#include<iostream.h>
typedef int DataType;
#include "astack.h"; //For the stack class
#include "apqueue.h" //for the priority queue class
//function uses both a priority queue and a stack object
void Ques(PQueues& pq)
{
Stack S; //declare a local stack to store data
int elt;
while(!pq.PQEmpty())
{
elt=pq.PQDelete();
S.Push(elt);
}
while(!S.StackEmpty())
cout<<S.Pop()<<" ";
cout << endl;
}
void main(void)
{
PQueue PQ;
int vals[]={2, 8, 55, 3, 12, 9} //declare an array of 6 integers
for(int i=0;i<6;i++)
PQ.PQInsert(vals[i]);
Ques(PQ);
}
PQueue PQ;
DataType x=5,y=3;
PQ.PQInsert(8);
PQ.PQInsert(9);
PQ.PQInsert(y);
x=PQ.PQDelete();
PQ.PQInsert(22);
while(!PQ.PQEmpty())
{
y=PQ.PQDelete(); //output 1(sequence)_____
cout << y << endl
}
cout << x << endl; //output 2_____
void F(Stack &S, DataType item)
{
Stack T;
DataType val;
while(!S.StackEmpty()&&(val=S.Pop())!=item)
T.Push(val);
if(!S.StackEmpty())
{
while(!T.StackEmpty())
S.Push(T.Pop());
S.Push(val);
}
}
#include<iostream.h>
#include<string.h>
#include<ctype.h>
typedef char DataType;
#include "aqueue.h"
#include "astack.h"
#include "apqueue.h"
void main(void)
{
Stack S;
Queue Q;
PQueue PQ;
char ch;
char sentence[]="StackQueue";
for(int i=0; i<strlen(sentence);i++)
PQ.PQInsert(sentence[i]);
while(!PQ.PQEmpty())
{
ch=PQ.PQDelete();
if(isupper(ch))
S.Push(ch);
else
Q.QInsert(ch);
}
while(!S.StackEmpty()) //A Prints the stack
{
ch=S.Pop();
cout << ch;
}
cout << endl;
while(!Q.QEmpty()) //B prints the queue
{
ch=Q.Qdelete();
cout<<ch;
}
cout <<endl;
}
struct Person
{
char name[32];
float salary;
};
The following items in the priority queue:
int operator < (Person a, Person b)
{
return strcmp(a.name, b.name)<0;
}
int operator< (Person a, Person b)
{
return a.salary>b.salary;
}