荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: huhaiming (一生只爱她), 信区: Program
标  题: 顺序队列
发信站: 荔园晨风BBS站 (Thu May  8 21:55:56 2003), 站内信件


自己改成类的形式

#include <stdio.h>
#define MAXSIZE 4
int queue[MAXSIZE];
int f=MAXSIZE-1,r=MAXSIZE-1;

//入队列
void EnQueue(int x)
{
        queue[r] = x;
        r = (r+1)%MAXSIZE;
}

//出队列
int DeQueue()
{
        int temp;
        temp = queue[f];
        f = (f+1)%MAXSIZE;
        return temp;
}

//判断队列是否满
int Full()
{
        return (r+1)%MAXSIZE == f;
}

//判断队列是否为空
int Empty()
{
        return r == f;
}

//主函数
void main()
{
        int i;
        for(i=0;i<MAXSIZE+1;i++)
                if(Full())
                        printf("The queue is full!\n");
                else
                        EnQueue(2*i);
        for(i=0;i<MAXSIZE+1;i++)
                if(Empty())
                        printf("The queue is Empty!\n");
                else
                        printf("%d is out!\n",DeQueue());
}


--

菩提本无树,明镜亦非台

本来无一物,何处惹尘埃

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 192.168.0.200]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店