// 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;
}

A simple stack的更多相关文章

  1. 栈(Stack) --- C# 自定义和微软官方的区别

    最近在学习算法基础,本篇文章作为一个记录,也算是一次实践和总结.(顺便也深入C#运行时学习一下) 目录 1. 栈是什么 2. Stack 自定义实现 3. Stack C#官方实现 4. 区别 5. ...

  2. Ionic2 Tutorial

    build your first app Now that you have Ionic and its dependencies installed, you can build your firs ...

  3. Using Qt to build an Omi App for iOS (and Android)

    JUNE 6, 2014 / HHARTZ Working on projects where the technology is pre-determined, it's often difficu ...

  4. Lua学习系列(一)

    从现在开始,打算学习一门新的脚本语言-lua. 1.什么是lua? a) lua1 • Lua 1.0 was implemented as a library, in less then 6000 ...

  5. 栈到CLR

    提起栈想必会听到这样几个关键词:后进先出,先进后出,入栈,出栈. 栈这种数据结构,数组完全可以代替其功能. 但是存在即是真理,其目的就是避免暴漏不必要的操作. 如角色一样,不同的情景或者角色拥有不同的 ...

  6. TensorFlow 2.0 新特性

    安装 TensorFlow 2.0 Alpha 本文仅仅介绍 Windows 的安装方式: pip install tensorflow==2.0.0-alpha0 # cpu 版本 pip inst ...

  7. Learn nodejs: Tutorials for Programmers of All Levels, 程序员每个阶段的示例

    https://stackify.com/learn-nodejs-tutorials/ What is Node.js? Node.js can be defined as a dynamic, c ...

  8. NT1_keras下搭建一个3层模型并且修改。

    In [1]: import keraskeras.__version__ C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py:36 ...

  9. 【IT笔试面试题整理】堆栈和队列

    如何准备: Whether you are asked to implement a simple stack / queue, or you are asked to implementa modi ...

随机推荐

  1. 用Java实现非阻塞通信

    用ServerSocket和Socket来编写服务器程序和客户程序,是Java网络编程的最基本的方式.这些服务器程序或客户程序在运行过程中常常会阻塞.例如当一个线程执行ServerSocket的acc ...

  2. 想做Android Wear开发?你得先搞明白这四件事

    手环和手表的腕上穿戴之争,随着Apple Watch发布和Android Wear不断完善而告一段落.尽管续航上略有缺陷,但手表以其类似手机可扩展的生态环境赢得了众多巨头的支持. Google曾透露, ...

  3. 网络流(最小费用最大流):POJ 2135 Farm Tour

    Farm Tour Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: ...

  4. 【扩展欧几里德】Vijos P1009 清帝之惑之康熙

    题目链接: https://vijos.org/p/1009 题目大意: 两个人,一个在坐标x,每天走m,一个在坐标y,每天走n,坐标长L,问几天后碰面. 题目思路: [扩展欧几里德] 根据同余方程的 ...

  5. HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)

    Problem Description Give you a lot of positive integers, just to find out how many prime numbers the ...

  6. [Locked] Generalized Abbreviation

    Write a function to generate the generalized abbreviations of a word. Example:Given word = "wor ...

  7. zoj 3365 灵活数字规律

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3365 #include <cstdio> #incl ...

  8. Spring与SpringMVC的容器关系分析

    Spring和SpringMVC作为Bean管理容器和MVC层的默认框架,已被众多WEB应用采用,而实际使用时,由于有了强大的注解功能,很多基于XML的配置方式已经被替代,但是在实际项目中,同时配置S ...

  9. DFU工作过程中USB机制

    在一级bootloader执行进入USB启动方式之后,设备进行枚举.枚举过程中会通过PC端发送命令对连接的USB设备进行枚举.当枚举成功之后,在PC端可以看到设备的盘符. 当设备能够被PC正确识别之后 ...

  10. poj 3154 Graveyard 贪心

    //poj 3154 //sep9 #include <iostream> #include <cmath> using namespace std; double a[204 ...