zoukankan      html  css  js  c++  java
  • 栈模型

    #include <stdio.h>
    struct stack
    {
        char space[512];
        int top;
    };
    struct stack stack = { { 0 }, 0 };
    int isempty(){
        return stack.top == 0;
    }
    int isfull(){
        return stack.top == 512;
    }
    void push(char val)
    {
        stack.space[stack.top] = val;
        stack.top++;
    }
    char pop()
    {
        stack.top--;
        return stack.space[stack.top];
    }
    int main()
    {
        if (!isfull())
            push('a');
        if (!isfull())
            push('b');
        if (!isfull())
            push('c');
        while (!isempty())
            putchar(pop());
        return 0;
    }

    #include <iostream>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    using namespace std;
    class Stack
    {
        public :
        void init();
        bool isEmpty();
        bool isFull();
        void push(int data);
        int pop();
    private:
        int space[1024];
        int top;
    };
    void Stack::init()
    {
        memset(space, 0, sizeof(space));
        top = 0;
    }
    bool Stack::isEmpty()
    {
        return top == 0;
    }
    bool Stack::isFull()
    {
        return top == 1024;
    }
    void Stack::push(int data)
    {
        space[top++] = data;
    }
    int Stack::pop()
    {
        return space[--top];
    }
    int main()
    {
        Stack s;
        s.init();
        if (!s.isFull())
            s.push(10);
        if (!s.isFull())
            s.push(20);
        if (!s.isFull())
            s.push(30);
        if (!s.isFull())
            s.push(40);
        if (!s.isFull())
            s.push(50);
        while (!s.isEmpty())
            cout << s.pop() << endl;
        return 0;
    }

  • 相关阅读:
    andorid jar/库源码解析之Butterknife
    JavaScript DOM 鼠标拖拽
    JavaScript JSON 与 AJAX
    JavaScript DOM 事件模型
    JavaScript DOM 样式操作
    JavaScript DOM 常用尺寸
    JavaScript 日期与计时器
    JavaScript DOM 基础
    JavaScript 数组
    JavaScript 对象拷贝
  • 原文地址:https://www.cnblogs.com/yuguangyuan/p/5848641.html
Copyright © 2011-2022 走看看