#include<iostream>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cctype>
#include<cstdio>
using namespace std;
#define MaxSize 100
typedef char ElemType;
typedef struct
{
ElemType data[MaxSize];
int front,rear;
} SqQueue;
void InitQueue(SqQueue *&q)
{ q=(SqQueue *)malloc (sizeof(SqQueue));
q->front=q->rear=0;
}
void DestroyQueue(SqQueue *&q)
{
free(q);
}
bool QueueEmpty(SqQueue *q)
{
return(q->front==q->rear);
}
bool enQueue(SqQueue *&q,ElemType e)
{ if ((q->rear+1)%MaxSize==q->front)
return false;
q->rear=(q->rear+1)%MaxSize;
q->data[q->rear]=e;
return true;
}
bool deQueue(SqQueue *&q,ElemType &e)
{ if (q->front==q->rear)
return false;
q->front=(q->front+1)%MaxSize;
e=q->data[q->front];
return true;
}
void solve(){
SqQueue *q;
InitQueue(q);
char c;
while(cin>>c){
if(isdigit(c))
enQueue(q,c);
else if(isalpha(c)){
char x;
if(deQueue(q,x))
printf("出队元素为:%c\n",x);
else
printf("队列为空\n");
}
else break;
}
}
int main(){
solve();
return 0;
}
#include<iostream>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cctype>
#include<cstdio>
#include<stack>
using namespace std;
#define MaxSize 100
typedef char ElemType;
typedef struct
{
ElemType data[MaxSize];
int front,rear;
} SqQueue;
void InitQueue(SqQueue *&q)
{ q=(SqQueue *)malloc (sizeof(SqQueue));
q->front=q->rear=0;
}
void DestroyQueue(SqQueue *&q)
{
free(q);
}
bool QueueEmpty(SqQueue *q)
{
return(q->front==q->rear);
}
bool enQueue(SqQueue *&q,ElemType e)
{ if ((q->rear+1)%MaxSize==q->front)
return false;
q->rear=(q->rear+1)%MaxSize;
q->data[q->rear]=e;
return true;
}
bool deQueue(SqQueue *&q,ElemType &e)
{ if (q->front==q->rear)
return false;
q->front=(q->front+1)%MaxSize;
e=q->data[q->front];
return true;
}
void solve(){
SqQueue *q;
InitQueue(q);
printf("初始队列:");
for(char i='a';i<='f';i++){
enQueue(q,i);
cout<<i<<" ";
}
cout<<endl;
char x;
stack<char> st;
while(deQueue(q,x)) st.push(x);
while(!st.empty()){
x=st.top();
st.pop();
enQueue(q,x);
}
printf("翻转后的队列为:");
while(deQueue(q,x)) cout<<x<<" ";
cout<<endl;
}
int main(){
solve();
return 0;
}
#include<iostream>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cctype>
#include<cstdio>
#include<stack>
using namespace std;
#define MaxSize 100
typedef int ElemType;
typedef struct
{
ElemType data[MaxSize];
int front,rear;
} SqQueue;
void InitQueue(SqQueue *&q)
{ q=(SqQueue *)malloc (sizeof(SqQueue));
q->front=q->rear=0;
}
void DestroyQueue(SqQueue *&q)
{
free(q);
}
bool QueueEmpty(SqQueue *q)
{
return(q->front==q->rear);
}
bool enQueue(SqQueue *&q,ElemType e)
{ if ((q->rear+1)%MaxSize==q->front)
return false;
q->rear=(q->rear+1)%MaxSize;
q->data[q->rear]=e;
return true;
}
bool deQueue(SqQueue *&q,ElemType &e)
{ if (q->front==q->rear)
return false;
q->front=(q->front+1)%MaxSize;
e=q->data[q->front];
return true;
}
void print(SqQueue *&q){
for(int i=0;;i++){
if(q->front+i==q->rear) break;
int p=(q->front+i)%MaxSize;
cout<<q->data[p+1]<<" ";
}
cout<<endl;
}
void solve(){
SqQueue *q;
InitQueue(q);
int x,num;
while(true){
printf("1:排队——输入排队病人的病历号,加入到病人排队队列中。\n");
printf("2:就诊——病人排队队列中最前面的病人就诊,并将其从队列中删除。\n");
printf("3:查看排队——从队首到队尾列出所有的排队病人的病历号。\n");
printf("4:不再排队,余下依次就诊——从队首到队尾列出所有的排队病人的病历号,并推出运行。\n");
printf("5:下班——退出运行。\n");
printf("请输入编号:");
cin>>x;
if(x==1){
printf("请输入病历号:");
cin>>num;
enQueue(q,num);
}
else if(x==2){
if(deQueue(q,num))printf("轮到%d看病了",num);
else printf("无人排队\n");
}
else if(x==3){
print(q);
}
else if(x==4){
int s;
while(deQueue(q,s)) cout<<s<<" ";
cout<<endl;
}
else break;
}
}
int main(){
solve();
return 0;
}