c#常用集合类使用练习(队列Queue、栈Stack、哈希表Hashtable和动态数组ArrayList)(2):
来源:互联网 发布:尼康 35 1.8 知乎 编辑:程序博客网 时间:2024/05/18 00:13
栈:stack,先进后出,仅允许在表的一端进行插入和删除运算(像一个坑,没错,就是坑,形象吧)
创建对象形式:
Stack 栈名 = new Stack( );
方法:
Push 栈顶数据推进;
Pop栈顶数据弹出;
Peek返回栈顶数据;
Clear清空栈;;
Contains检查栈中是否包含某个数据的操作;
说明:,Push和Pop每操作一次只能添加或删除一个数据;
源代码:
Console.WriteLine(); //Stack栈:先进后出,像一个坑 //实例化 Stack st = new Stack(); //将对象插入Stack顶部 st.Push(1); st.Push(2); st.Push(3); st.Push(4); st.Push(5); //对象个数 Console.Write("对象个数:"); Console.WriteLine(st.Count); // Console.WriteLine(st.Peek()); //返回栈顶数据 foreach (int ss in st) { Console.WriteLine(ss); } //清除一个对象 Console.WriteLine("清除对象" + st.Pop()); Console.Write("对象个数:"); Console.WriteLine(st.Count); //遍历 // Console.WriteLine(st.Peek()); foreach (int ss in st) { Console.WriteLine(ss); } //检查是否包含某个数据,若有,返回true,若无,返回false Console.WriteLine(st.Contains(2)); st.Clear(); Console.Write("对象个数:"); Console.WriteLine(st.Count);
阅读全文
2 0
- c#常用集合类使用练习(队列Queue、栈Stack、哈希表Hashtable和动态数组ArrayList)(2):
- c#常用集合类使用练习(队列Queue、栈Stack、哈希表Hashtable和动态数组ArrayList)(1):
- c#常用集合类使用练习(队列Queue、栈Stack、哈希表Hashtable和动态数组ArrayList)(3):
- c#常用集合类使用练习(队列Queue、栈Stack、哈希表Hashtable和动态数组ArrayList)(4):
- [c#基础知识] C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C#集合类(Array、Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C#集合类(Array、Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C#集合类(Array、Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C#集合类(Array、Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C#集合类(Array、Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- js中var a= b || c的写法
- Linux之redhat通过shell脚本安装虚拟机教程
- Oracle 锁表查询
- 点击UIWebView获取图片的URL的两种方法
- Android逆向-记录某密码管理APP的设计逻辑
- c#常用集合类使用练习(队列Queue、栈Stack、哈希表Hashtable和动态数组ArrayList)(2):
- XML 文件解析 利用反射原理 JavaBean 工具类
- ES6学习笔记(五)
- GlusterFS创建volume失败的解决方法(* or a prefix of it is already part of a volume)
- Android tablayout集合fragment使用
- 远程连接Linux系统下MySQL数据库失败解决方法
- CentOS6.9用yum安装gccError:Cannot find a valid baseurl for repo:base。用yum装httpd80端口被占用。
- Spark基本术语表+基本架构+基本提交运行模式
- a trap in pointer moving