Chinaunix首页 | 论坛 | 博客
  • 博客访问: 174143
  • 博文数量: 48
  • 博客积分: 2085
  • 博客等级: 大尉
  • 技术积分: 420
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-20 15:22
文章分类

全部博文(48)

文章存档

2013年(1)

2012年(1)

2011年(1)

2010年(16)

2009年(29)

分类:

2009-10-20 16:00:14

  #include
using namespace std;
#define NULL 0  
#define MAXSIZE 100  
typedef int Elemtype;  
typedef struct
{ Elemtype *base;  
int front ;  
int rear;  
}SqQueue;  

void InitQueue(SqQueue *&Q)  
{  
Q=(SqQueue *)malloc(sizeof(SqQueue));
Q->base=(Elemtype *)malloc( MAXSIZE *sizeof(Elemtype));  
if(!Q->base)
{ printf("The InitQueue is fail!");  
return;  
}  
Q->front=Q->rear=0;  
}  

void EnQueue(SqQueue *Q,Elemtype e)  
{  
if( (Q->rear+1)%MAXSIZE==Q->front )
{ printf("\nThe EnQueue is fail!");  
return;  
}  
Q->base[Q->rear]=e;  
Q->rear=(Q->rear+1)%MAXSIZE;  
}  

void DeQueue(SqQueue *Q,Elemtype *e)  
{  
if(Q->rear==Q->front)
{
printf("\nThe DeQueue is fail,the Queue is empty!");  
return;  
}  
*e=Q->base[Q->front];  
Q->front=(Q->front+1)%MAXSIZE;  
}  

int main()  
{ SqQueue *que;  
Elemtype num,s;  
que=NULL;  
InitQueue(que);  
scanf("%d",&num);  
while(num!=-1)  
{  
EnQueue(que,num);  
scanf("%d",&num);  
}  
cin.get();
printf("\nThe result of DeQueue is :\n");  
while (que->front!=que->rear)  
{
DeQueue(que,&s);
cout<getchar();  
}  
return 0;
}
 
阅读(1314) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~