zoukankan      html  css  js  c++  java
  • 队列的练习

    #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;
    //}
  • 相关阅读:
    Valid Anagram
    Spiral Matrix II
    Spiral Matrix
    Kth Smallest Element in a BST
    Count Primes
    javascript 判断浏览器
    javascript 数值交换技巧
    EntityFramework 6 分页模式
    JSON.parse 和 JSON.stringify
    CSS z-index
  • 原文地址:https://www.cnblogs.com/qingcheng/p/3099069.html
Copyright © 2011-2022 走看看