qingcheng奕  

 

#include <iostream>

const int SIZE = 101;
typedef struct queue
{
    int front,rear;
    int data[SIZE];
};

void init(struct queue *_queue)
{
    _queue->front = _queue->rear = 0;
}
bool isEmpty(struct queue *_queue)
{
    return _queue->front ==_queue->rear;
}
bool isFull(struct queue *_queue)
{
    return _queue->rear == SIZE;
}
void push(struct queue *_queue,int _data)
{
    if(!isFull(_queue))
    {
        _queue->data[_queue->rear] = _data;
        _queue->rear++;
    }
    else
    {
        printf("队列已满");
        exit(1);
    }
}
int pop(struct queue *_queue)
{
    int temp;
    if(!isEmpty(_queue))
    {
        
        temp = _queue->data[_queue->front];
        _queue->front++;
    }
    else
    {
        printf("队列为空");
        exit(1);
    }
    return temp;
}
//int main()
//{
//    queue myqueue;
//    init(&myqueue);
//    for(int i = 0;i<100;i++)
//    {
//        push(&myqueue,i);
//    }
//    for(int i = 0;i<100;i++)
//    {
//        printf("%d\n",pop(&myqueue));
//    }
//    return 0;
//}

 

posted on 2013-05-25 17:05  qingcheng奕  阅读(91)  评论(0编辑  收藏  举报