标签:
// 队列的数组实现
#include <cstdio>
#include <cstdlib>
#define maxsize 100
//#define _OJ_
typedef struct Lnode
{
int top;
int base;
int *array;
} qnode, *queue;
void
creat_queue(queue q)
{
q->array = (int *) malloc (sizeof(int) * maxsize);
q->top = q->base = 0;
}
int
isempty(queue q)
{
if(q->top - q->base == 0)
return 1;
else
return 0;
}
void
Enqueue(queue q)
{
int x;
scanf("%d", &x);
//printf("%d\n", x);
q->array[q->top++] = x;
}
int
DEqueue(queue q)
{
int e;
e = q->array[q->base++];
return e;
}
void
print(queue q)
{
int i;
for(i = q->base;i < q->top; i++) {
printf("%d\n", q->array[i]);
}
}
int main(int argc, char const *argv[]) {
#ifndef _OJ_ //ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int i, n;
queue q;
creat_queue(q);
printf("null == %d\n", isempty(q));
scanf("%d", &n);
while (n--) {
printf("%d\n", n);
Enqueue(q);
}
while (q->base != q->top) {
printf("out == %d\n", DEqueue(q));
}
//不知为什么此处条件不可以为n--
return 0;
}
标签:
原文地址:http://www.cnblogs.com/airfand/p/4925732.html