后进先出 stack、 先进先出Queue
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
undostack = new Stack();
} Stack undostack;
private void button1_Click(object sender, EventArgs e)
{
undostack.Push(textBox1.Text);
} private void button2_Click(object sender, EventArgs e)
{
if (undostack.Count != )
{
string txt = (string)undostack.Pop();
if (txt != null)
{
textBox2.Text = txt;
}
}
}
}
}
| 序号 | 方法名 & 描述 |
|---|---|
| 1 | public virtual void Clear(); 从 Stack 中移除所有的元素。 |
| 2 | public virtual bool Contains( object obj ); 判断某个元素是否在 Stack 中。 |
| 3 | public virtual object Peek(); 返回在 Stack 的顶部的对象,但不移除它。 |
| 4 | public virtual object Pop(); 移除并返回在 Stack 的顶部的对象。 |
| 5 | public virtual void Push( object obj ); 向 Stack 的顶部添加一个对象。 |
| 6 | public virtual object[] ToArray(); 复制 Stack 到一个新的数组中。 |
button1点击后 Textbox1的字符push进stack中。点击button2后,将堆栈中后进的元素挨个在TextBox2中显示.
后进先出 stack、 先进先出Queue的更多相关文章
- LinkedList、Stack、Queue、PriorityQueue的总结
1.这几种容器的特点 都是按照顺序来存储元素. 取元素的时候的不同点: LinkedList:按照下标随意取元素 Stack:后进先出取元素 Queue:先进先出取元素 PriorityQueue:按 ...
- [STL]deque和stack、queue
怎么说呢,deque是一种双向开口的连续线性空间,至少逻辑上看上去是这样.然而事实上却没有那么简单,准确来说deque其实是一种分段连续空间,因此其实现以及各种操作比vector复杂的多. 一.deq ...
- 剑指offer——stack与queue的互相实现
我们知道,stack和queue是C++中常见的container.下面,我们来探究下如何以stack来实现queue,以及如何用queue来实现stack. 首先,先了解下stack与queue的基 ...
- 特殊集合(stack、queue、hashtable的示例及练习)
特殊集合:stack,queue,hashtable stack:先进后出,一个一个的赋值一个一个的取值,按照顺序. .count 取集合内元素的个数 .push() ...
- 带你深入理解STL之Stack和Queue
上一篇博客,带你深入理解STL之Deque容器中详细介绍了deque容器的源码实现方式.结合前面介绍的两个容器vector和list,在使用的过程中,我们确实要知道在什么情况下需要选择恰当的容器来满足 ...
- 04--STL序列容器(Stack和Queue)
总括: stack和queue不支持迭代 一:栈Stack (一)栈的简介 stack是堆栈容器,是一种“先进后出”的容器. stack是简单地装饰deque容器而成为另外的一种容器. (二)栈的默认 ...
- 容器适配器(stack、 queue 、priority_queue)源码浅析与使用示例
一.容器适配器 stack queue priority_queue stack.queue.priority_queue 都不支持任一种迭代器,它们都是容器适配器类型,stack是用vector/d ...
- java中List、Map、Set、Collection、Stack、Queue等的使用
java中这几个东西是比较常用的,虽然我用的不多,也正是因为用的不多,所以我一直搞不清楚他们之间的具体用法以及相互之间的关系,现在特单独作为一个东西来总结一下. 本文参考一下资料: 1.<jav ...
- 检索 04 --Stack栈 Queue队列 Hashtable哈希表
//Stack 先进后出 没有索引 Stack st = new Stack(); st.Push(12); st.Push(11); st.Push(22); st.Push(34); st.Pus ...
- C++ STL——stack和queue
目录 一 stack容器 二 queue容器 注:原创不易,转载请务必注明原作者和出处,感谢支持! 注:内容来自某培训课程,不一定完全正确! 栈和队列作为经典的数据结构,我们再熟悉不过了.C++ ST ...
随机推荐
- struts2杂记(一)——使用doubleSelect
一.前言 这段时间忙的要死,做项目,学框架,时间根本不够用,只能尽量抽出时间记录自己学过的东西. 1.1.doubleSelect 在之前学习中,我们使用过二级列表,相信很多人都理解其原理,在stru ...
- push方法的兼容性问题
在IE8及以下中,不支持aplly方法中的第二个参数是 伪数组 需要对push方法进行封装. 将 push 的判断,放入一个沙箱中: 好处:在页面加载的时候就会执行这段代码,保证了代码只会检测一次 以 ...
- jQuery orbit 幻灯片
在线实例 默认 带缩略图 带描述 使用方法 <div class="wrap" style="width: 565px; height: 290px; margin ...
- Java学习-序列化
参考资料: http://www.2cto.com/kf/201405/305380.html http://www.cnblogs.com/xdp-gacl/p/3777987.html 序列化 ...
- ArcGIS Engine开发之地图基本操作(1)
ArcGIS提供的各类数据形式以及相应接口 1. 空间数据 在GIS软件中,空间数据有多种不同的形式存在.按照不同的划分标准可以分为矢量数据和栅格数据.GIS格式数据和非GIS格式数据(CAD格式). ...
- 错误:当你使用id作为sharepoint的自定义页面的查询参数时,总会提示项目不存在!
No item exists at http://SERVER/SITE/mypage.aspx?ID=1. It may have been deleted or renamed by anothe ...
- iOS中的各种id
 网卡Mac地址会随机化 
- Java之递归求和的两张方法
方法一: package com.smbea.demo; public class Student { private int sum = 0; /** * 递归求和 * @param num */ ...
- vim的高亮查找操作
使用了VIM这么久,却一直无法牢记一些基本的操作指令.今天查找一个关键字时,想不起来怎么查找“下一个”,于是google之并解决,顺便把有用的都贴过来罢. 查找指令:/xxx 往下查找?xxx 往上 ...
- github常用操作
1.创建一个新的repository: $cd ~/hello-world //到hello-world目录,本地目录名与repository的名字不一定相同 $git init ...