• 栈的练习


    //zhan和队列,你就实现一个之后,插入1-100,然后取出1-100
    #include <iostream>
     
    typedef int datatype;
    #define SIZE 100
    typedef struct stack{
        datatype data[100];
        int head;
    }_stack;
    void init(struct stack *_stack)
    {
        for(int i = 0;i<100;i++)
            (*_stack).data[i] = 0;
        (*_stack).head = 0;
    }
    bool isEmpty(struct stack *_stack)
    {
        return _stack->head == 0;
    }
    bool isFull(struct stack *_stack)
    {
        return _stack->head == SIZE;
    }
    void push(struct stack *_stack,datatype data)
    {
        if(!isFull(_stack))
        {
        (*_stack).data[(*_stack).head] = data;
        (*_stack).head++;
        }
        else
        {
            printf("栈满");
            exit(1);
        }
    }
    
    datatype pop(struct stack *_stack)
    {
        datatype tmp;
        if(!isEmpty(_stack))
        {
            _stack->head--;
            tmp = _stack->data[_stack->head];
        }
        else
        {
            printf("栈空");
            exit(1);
        }
    }
    //int main()
    //{   
    //    stack mystack;
    //    init(&mystack);
    //    for(int i = 0;i<100;i++)
    //    {
    //        push(&mystack,i);
    //    }
    //    for(int i = 0;i<100;i++)
    //    {
    //        printf("%d\n" ,pop(&mystack));
    //    }
    //    return 0;
    //}
  • 相关阅读:
    MAC上Vue的一些安装及配置
    MySQL
    git
    win7系统的用户怎么去掉用户账户控制?
    JS
    IDEA使用总结
    Mybatis
    codeforces cf educatonal round 57(div2) D. Easy Problem
    codeforces round#509(div2) E. Tree Reconstruction
    codeforces round#509(div2) D. Glider
  • 原文地址:https://www.cnblogs.com/qingcheng/p/3099068.html
Copyright © 2020-2023  润新知