// 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. ParentWindow属性及其一系列函数的作用——适合于那些不需要父控件管理内存释放的子控件

    TWinControl = class(TControl) property ParentWindow: HWnd read FParentWindow write SetParentWindow; ...

  2. Going Home(最小费用最大流)

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16200   Accepted: 8283 Description On a ...

  3. updatepanel刷新后重新加载js脚本问题

    在页尾加 <script type="text/javascript"> Sys.WebForms.PageRequestManager.getInstance().a ...

  4. 【模拟】Codeforces 699A Launch of Collider

    题目链接: http://codeforces.com/problemset/problem/699/A 题目大意: 给N个点,向左或向右运动,速度均为1,问最早什么时候有两个点相撞.无解输出-1 题 ...

  5. sql server 删除索引的语句

    DROP INDEX index_name ON talbe_nameDROP INDEX IX_TBlueyBook_10 ON 表名

  6. Ubuntu下安装Skyeye

    ubuntu12下安装skyeye1.3.2 1.首先安装skyeye的依赖包,比如gtk的依赖,一般Ubuntu 都默认安装了,稳妥起见,运行下面的代码: sudo apt-get install ...

  7. UVALive 7148 LRIP 14年上海区域赛K题 树分治

    题意 n个点组成一棵树, 带有点权. 求最长不降的路径的长度, 且路径上最大值最小值之差不超过D. 显然是树分治, 但是分治之后如何维护答案呢. 假设当前重心为g, 分别记录g出发不降路径的长度,以及 ...

  8. baidu面试题

    百度:http://blog.chinaunix.net/uid-26602509-id-3306451.html http://lvwenwen.iteye.com/blog/1504379

  9. hdu 4579 博弈+区间dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 #include <cstdio> #include <cstring> ...

  10. 怎么用copy关键字

    出题者简介: 孙源(sunnyxx),目前就职于百度 整理者简介:陈奕龙,目前就职于滴滴出行. 转载者:豆电雨(starain)微信:doudianyu 用途: NSString.NSArray.NS ...