using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace StackAndQueue
{
class Program
{
static void Main(string[] args)
{
//栈是先进后出
Stack<string> fruits=new Stack<string>(); //元素入栈用push,就是向栈中添加元素
fruits.Push("Apple");
fruits.Push("pear");
fruits.Push("grape");
fruits.Push("watermelon"); //获取stack 中的元素个数
int num = fruits.Count(); //pop出栈,返回最最后入栈的元素并删除栈中的元素
string s1 = fruits.Pop(); //Peek返回最后入栈的元素,不删除栈中的元素
string s2 = fruits.Peek(); //清空栈中元素
fruits.Clear(); //队列与栈不同,遵循先进先出的原则
Queue<string> name = new Queue<string> ( ); //入队列,向队列中添加元素
name.Enqueue ("一" );
name.Enqueue ("二");
name.Enqueue ("三" );
name.Enqueue ( "四"); //获取队列中的元素个数
int a=name.Count ( ); //判断指定元素是否包含在队列中
bool b=name.Contains ("三"); //出队列,使用Dequeue出队列会获取队列中最下方的元素,也就是先进入的元素,然后删除队列中的该元素
string str1= name.Dequeue ( ); //使用peek 出队列,只会讲最下方的元素获取,不会将元素从队列中删除
string str2=name.Peek ( ); //清空队列
name.Clear ( );
}
}
}

最新文章

  1. 从C#到Objective-C,循序渐进学习苹果开发(2)--Objective-C和C#的差异
  2. ls 只显示目录
  3. angular的canvas画图例子
  4. hadoop spark学习笔记
  5. Cent OS 6 主机名设置
  6. hibernate id生成器配置
  7. WCF 新手教程二
  8. Ural 1046 Geometrical Dreams(解方程+计算几何)
  9. Oracle select into from 和 insert into select
  10. Android Studio 如何将包名按层级展示
  11. Sql Server 数据库中调用dll文件
  12. centos 下安装pptp (vpn) 的方法
  13. Codeforces Round #436 (Div. 2) D. Make a Permutation!
  14. 初识MySQL数据库的各种CMD命令窗口下的指令
  15. Numpy1
  16. 设置字体格式,加粗,regular,light
  17. org.hibernate.InvalidMappingException: Could not parse mapping document from无法创建sessionFactory
  18. 洛谷.2590.[ZJOI2008]树的统计(树分块)
  19. LeetCode 709 To Lower Case 解题报告
  20. 27.反射2.md

热门文章

  1. vue自学入门-4(vue slot)
  2. JS 动态改变浏览器title标题
  3. 将内裤穿在外面的男人(mysql)
  4. [Python]find_all函数 2020.2.7
  5. 假期学习【五】RDD编程实验四
  6. Java8之Stream详解
  7. Error Code : 1064 You have an error in your SQL syntax; check the manual that corresponds to your My
  8. [CQOI2009] 中位数 - 桶
  9. jsp报错java.io.IOException: Stream closed
  10. python面试的100题(18)