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

A simple stack的更多相关文章
- 栈(Stack) --- C# 自定义和微软官方的区别
最近在学习算法基础,本篇文章作为一个记录,也算是一次实践和总结.(顺便也深入C#运行时学习一下) 目录 1. 栈是什么 2. Stack 自定义实现 3. Stack C#官方实现 4. 区别 5. ...
- Ionic2 Tutorial
build your first app Now that you have Ionic and its dependencies installed, you can build your firs ...
- 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 ...
- Lua学习系列(一)
从现在开始,打算学习一门新的脚本语言-lua. 1.什么是lua? a) lua1 • Lua 1.0 was implemented as a library, in less then 6000 ...
- 栈到CLR
提起栈想必会听到这样几个关键词:后进先出,先进后出,入栈,出栈. 栈这种数据结构,数组完全可以代替其功能. 但是存在即是真理,其目的就是避免暴漏不必要的操作. 如角色一样,不同的情景或者角色拥有不同的 ...
- TensorFlow 2.0 新特性
安装 TensorFlow 2.0 Alpha 本文仅仅介绍 Windows 的安装方式: pip install tensorflow==2.0.0-alpha0 # cpu 版本 pip inst ...
- 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 ...
- NT1_keras下搭建一个3层模型并且修改。
In [1]: import keraskeras.__version__ C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py:36 ...
- 【IT笔试面试题整理】堆栈和队列
如何准备: Whether you are asked to implement a simple stack / queue, or you are asked to implementa modi ...
随机推荐
- Tomcat error: A child container failed during start
Tomcat error: A child container failed during start java.lang.NoClassDefFoundError: org/quartz/Sched ...
- If one session has a shared or exclusive lock on record R in an index, another session cannot insert
If one session has a shared or exclusive lock on record R in an index, another session cannot insert ...
- 【二分】NEERC15 L Landscape Improved(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
题目链接: http://codeforces.com/gym/100851 题目大意: 一个宽度为N的网格图,i上有h[i]高的方块.现在你有W个方块,问怎么放使得最终的最高点最高. 只要一个格子的 ...
- Codeforces Round #216 (Div. 2) E. Valera and Queries 树状数组 离线处理
题意:n个线段[Li, Ri], m次询问, 每次询问由cnt个点组成,输出包含cnt个点中任意一个点的线段的总数. 由于是无修改的,所以我们首先应该往离线上想, 不过我是没想出来. 首先反着做,先求 ...
- RabbitMQ-清空队列中(一个channel或连接中)的Unacknowledged状态的消息
清空所有:nack 时将参数delivery-tag设为0,multiple设为1. 清空小于等于某delivery-tag的所有消息:nack 时将参数delivery-tag设为正数(介于1和92 ...
- JS中timestamp日期类型的转换
在JS中获取timestamp:var timestamp=Math.round(new Date().getTime()/1000); 在JS中将timestamp转换为Date: Date.pro ...
- Android项目实战--手机卫士20--拿到已经安装了的程序以及程序管理主界面
好了,之前我们就讲了高级工具里面的短信备份与还原,那么我们高级工具里面的功能就基本上完成的啦,还有一个叫程序锁的功能而已,但我们今天先不做它先,我们先把我们的程序管理这个功能完成先. 先让大家看一下我 ...
- [Angular 2] Create a simple search Pipe
This lesson shows you how to create a component and pass its properties as it updates into a Pipe to ...
- Android xml 解析
XML 经常使用的三种解析方式: DOM: 所有载入到内存,生成一个树状结构,占用内存比較大. SAJ: 採用事件驱动,速度快,效率高,不支持回退. PULL:也是採用事件驱动,语法简洁. 步骤: 1 ...
- poj 3735 大数量反复操作问题(矩阵高速幂)
题意:一个一维数组,3种操作: a: 第i个数+1,b: 第i个数=0 ,c::交换某俩处的数. 由三种基本操作构成一组序列,反复该序列m次(m<10^9),问结果 属于一种综合操作反复型: ...