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 ...
随机推荐
- Context Switch Definition
A context switch (also sometimes referred to as a process switch or a task switch) is the switching ...
- MySQL基本查询语句练习
努力很久只为获得别人尊重的眼光. ——我是,董宏宇,我为自己代言. 技术交流QQ:1358506549(请注明你的来意) use xsx; CREATE TABLE Course( Cno char( ...
- java学习之关键字
java语言当中的关键字,之所以存在,是为了告诉编译器如何解释一段有意义的代码段.比如说 /**需求:演示java中关键字存在的含义步骤:用class,public,static,void等说明什么是 ...
- 【效率】FIND
文档 HTML Flash CSS 字体 命名颜色 工具 IMG
- (转载)遍历memcache中已缓存的key
(转载)http://www.cnblogs.com/ainiaa/archive/2011/03/11/1981108.html 最近需要做一个缓存管理的功能.其中有一个需要模糊匹配memcache ...
- 动态规划(二维背包问题):UVAoj 473
Raucous Rockers You just inherited the rights to n previously unreleased songs recorded by the pop ...
- SRM149 - SRM150(少SRM150-DIV1-LV3)
SRM 149 DIV2 1000pt 题意: 对于n个人,第i人有pi的钱.将他们分成不超过四个组,每组统一交费x,对每个人,若他拥有的钱超过x则交费,否则不交费.问最多能使这些人交多少钱. 1&l ...
- 十大纺织品、布料、面料品牌排名 - 十大品牌 - 中国品牌网 Chinapp.com
十大纺织品.布料.面料品牌排名 - 十大品牌 - 中国品牌网 Chinapp.com 十大纺织品.布料.面料品牌排名
- python BDD&TDD
教程一:行为驱动开发(BDD) 基于Python的行为驱动开发实战: http://python.jobbole.com/81303/ 基于Python的行为驱动开发实战 英语原文地址: http:/ ...
- JAX-WS + Spring 开发webservice
通过几天的时间研究了下使用jax-ws来开发webservice,看了网上的一些资料总结出jax-ws的开发大概分为两种. 以下项目使用的spring3.0,jar包可以到官网下载 第一种:使用独立的 ...