// 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. Caption,Text,WindowText的区别——TControl也有FText,是为了模拟一个窗口

    TControl = class(TComponent) // 控件的Windows功能从TControl开始 property Caption: TCaption read GetText writ ...

  2. [OpenGL]VS2010配置OpenGL开发环境

    opengl概述 OpenGL(Open Graphics Library)是一个跨编程语言.跨平台的专业图形程序接口. OpenGL是SGI公司开发的一套计算机图形处理系统,是图形硬件的软件接口,任 ...

  3. [LeetCode#110, 112, 113]Balanced Binary Tree, Path Sum, Path Sum II

    Problem 1 [Balanced Binary Tree] Given a binary tree, determine if it is height-balanced. For this p ...

  4. ZKW费用流修正

    #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #inc ...

  5. BZOJ 1059 [ZJOI2007]矩阵游戏

    1059: [ZJOI2007]矩阵游戏 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2707  Solved: 1322[Submit][Stat ...

  6. WordPress /wp-admin/users.php畸形s参数路径泄漏漏洞

    漏洞版本: WordPress 2.7.x WordPress 2.8.x WordPress 2.9.x WordPress 3.0.x WordPress 3.1.x WordPress 3.2. ...

  7. CMOS Sensor的调试经验分享

    转自:http://bbs.52rd.com/forum.php?mod=viewthread&tid=276351 CMOS Sensor的调试经验分享 我这里要介绍的就是CMOS摄像头的一 ...

  8. 数据结构(线段树):SPOJ GSS3 - Can you answer these queries III

    GSS3 - Can you answer these queries III You are given a sequence A of N (N <= 50000) integers bet ...

  9. PowerDesigner自定义Word导出格式

    本文主要讲解如何将PDM的表结构导出成word以及如何自定义导出格式和显示效果,希望对大家有所帮助...(以下步骤以PowerDesigner 15版本为例) 一.新建导出报表,进入报表设计界面: 1 ...

  10. WdatePicker 控制选择范围

    1. 跨无限级框架显示 无论你把日期控件放在哪里,你都不需要担心会被外层的iframe所遮挡进而影响客户体验,因为My97日期控件是可以跨无限级框架显示的 示例2-7 跨无限级框架演示 可无限跨越框架 ...