#include
#include
#include
#include
using namespace std;
struct queue
{ int num;
queue *next;};
void push(queue *&s, int a)
{
queue *r=new queue;
r->num=a;
r->next=s;
s=r;
}
void pop(queue *&S1, int &i)
{
queue *tmp;
tmp=S1;
i=S1->num;
S1=S1->next;
delete tmp;
}
int main() {
srand(time(NULL));
setlocale(LC_ALL, "rus");
cout<<"queue size: ";
int n, r=0, x=0; cin>>n;
queue *S1=NULL, *S2=NULL;
int max;
cout<<"\nqueue: ";
for(int i=0, a; i
{ a=rand()% 99 + 1;
if(i==0) max=a;
if(a>max) max=a;
push(S1, a);
cout<
for (int i=0; i
{pop(S1, r);
if(r==max)
{ push(S2, 0); x++; }
push(S2, r); }
cout<<"\nNext\n";
getch();
cout<<"\nMax="<
cout<<"\nResult: ";
for (int i=0; i
{
pop(S2,r);
cout<
}
return 0;
}
Do'stlaringiz bilan baham: |