• A simple stack


    // simple stack.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdafx.h"
    #include<iostream>
    using namespace std;
    const int SIZE = 100;
    class Stack
    {
        public:
            void init()
            {
                position = 0;
            }
            char push(char ch);
            char pop();
    private:
        char stk[SIZE];
        int position;
    };


    char Stack::push(char ch)
    {
        if (position == SIZE)
        {
            cout << endl << "stack is full" << endl;
            return 0;
        }
        stk[position++] = ch;
        return ch;
    }

    char Stack::pop()
    {
        if (position ==0)
        {
            cout << endl << "stack is null" << endl;
            return 0;
        }
       
        return stk[--position] ;
    }
    int main()
    {
        Stack s;
        s.init();
        char ch;
        cin >> ch;
        while (ch != '!'&&s.push(ch))
            cin >> ch;
        cout << "data in stack:";
        while (ch = s.pop())
            cout << ch;
        system("pause");
        return 0;
    }

    图像 6

  • 相关阅读:
    Spring Boot 之Profile
    Spring Security初识
    Github使用进阶
    数据库JDBC
    Java内存模型(JMM)的可见性
    Spring Boot 整合Spring Data JPA
    Git版本控制工具初识
    Linux美化——终端提示符
    Python's Exception 层级结构
    试写Python内建函数range()
  • 原文地址:https://www.cnblogs.com/summercloud/p/5518587.html
Copyright © 2020-2023  润新知