新建一个栈,读取标准输入3个整数3 4 5,入栈3 4 5,依次出栈,打印 5 4 3,新建循环队列(Maxsize为5),读取标准输入3 4 5 6 7,入队7时,队满,打印false,然后依次出队,输出 3 4 5 6
代码如下:
#include<stdio.h>
#include<stdlib.h>
#define Maxsize 100
typedef int Elemtype;
typedef struct
{
Elemtype data[5];
int top;
}SqStack;
void Initstack(SqStack &s)
{
s.top=-1;
}
bool Emptystack(SqStack s)
{
if(s.top==-1)
{
return true;
}
else
{
return false;
}
}
bool push(SqStack &s,Elemtype x)
{
if(s.top==Maxsize-1)
{
return false;
}
s.data[++s.top]=x;
return true;
}
bool pop(SqStack &s,Elemtype &x)
{
if(s.top==-1)
{
return false;
}
x=s.data[s.top--];
return true;
}
typedef struct
{
Elemtype data[5];
int rear,front;
}SqQueue;
void InitQueue( SqQueue &Q)
{
Q.rear=Q.front=0;
}
bool EmptyQueue(SqQueue Q)
{