- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 10
- struct student
- {
- int data[MAX];
- int top;
- };
- void Init(struct student *s)
- {
- s->top = -1;
- }
- int IsEmpty(struct student *s)
- {
- if(s->top == -1)
- return 1;
- return 0;
- }
- int IsFull(struct student *s)
- {
- if(s->top == MAX - 1)
- return 1;
- return 0;
- }
- int Push(struct student *s,int x)
- {
- if(IsFull(s))
- return 0;
- s->top++;
- s->data[s->top] = x;
- return 1;
- }
- int Pop(struct student *s)
- {
- int b;
- if(IsEmpty(s))
- return 0;
- b = s->data[s->top];
- s->top --;
- return b;
- }
- void main()
- {
- struct student *stu;
- stu = (struct student *)malloc(sizeof(struct student));
- Init(stu);
- for(int i=0;i<MAX;i++)
- {
- Push(stu,i);
- }
- while(!IsEmpty(stu))
- {
- int j;
- j = Pop(stu);
- printf("%d ",j);
- }
- }
C语言:队列
最新推荐文章于 2023-08-24 22:44:46 发布