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 ...
随机推荐
- BZOJ 1048 [HAOI2007]分割矩阵
1048: [HAOI2007]分割矩阵 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 623 Solved: 449[Submit][Status ...
- Javascript 面向对象编程(一):封装 by 阮一峰
<Javascript高级程序设计(第二版)>(Professional JavaScript for Web Developers, 2nd Edition) 它们都是非常优秀的Java ...
- 扩展KMP模板
注意:需要用特殊符号隔开 1 struct ExKmp{ void Init(){ memset(f,,sizeof(f)); memset(r,,sizeof(r)); } void Get_Fai ...
- 线段树(维护最大值):HDU Billboard
Billboard Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- bzoj 1055 [HAOI2008]玩具取名(区间DP)
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1258 Solved: 729[Submit][Statu ...
- Servlet工作原理
Servlet生命周期分为三个阶段: 1,初始化阶段 调用init()方法 2,响应客户请求阶段 调用service()方法 3,终止阶段 调用destroy()方法 Servlet初始化阶段: 在 ...
- apache POI 导出excel相关方法
apache POI 操作excel无比强大.同时有操作word和ppt的接口. 下面讲解poi中常用方法. 1,设置列宽 HSSFSheet sheet = wb.getSheetAt(0); sh ...
- php开启curl和openssl
php开启curl和openssl 开启php curl函数库的步骤 1).去掉windows/php.ini 文件里;extension=php_curl.dll前面的; /*用 echo phpi ...
- docker安装lnmp 环境
docker基础知识请转 docker中文文档:http://docker-doc.readthedocs.io/zh_CN/latest/index.html docker英文文档: https:/ ...
- WebChat 清爽来袭 -- JavaChat系统Ⅳ
题记: WebChat 依然搭配的是 JavaChat 服务器,在不修改原来服务器代码的情况下进行使用终端的扩展. 此次项目的难点在于,Action/Servlet ...