蓝鸥Unity开发基础二——课时25 栈和队列
2016-09-08 10:20
204 查看
蓝鸥Unity开发基础二——课时25 栈和队列一、栈和队列
栈遵循后进先出的原则
队列遵循先进后出的原则
栈和队列根据需要容量自动增加
栈和队列都允许重复元素
推荐视频讲师博客:http://11165165.blog.51cto.com/
using System;
using System.Collections.Generic;
namespace Lesson_25
{
class MainClass
{
public static void Main (string[] args)
{
Stack<string> s = new Stack<string> ();
int count = s.Count;
s.Clear ();
bool b = s.Contains ("老王");
//把元素入栈
s.Push("老王");
s.Push("老张");
s.Push("小明");
//Pop把元素出栈,栈中就没有这个元素了
string s1 = s.Pop ();
Console.WriteLine (s1);
string s2 = s.Pop ();
Console.WriteLine (s2);
string s3= s.Pop ();
Console.WriteLine (s3);
}
}
}
using System;
using System.Collections.Generic;
namespace Lesson_25
{
class MainClass
{
public static void Main (string[] args)
{
// Stack<string> s = new Stack<string> ();
// int count = s.Count;
// s.Clear ();
// bool b = s.Contains ("老王");
//把元素入栈
// s.Push("老王");
// s.Push("老张");
// s.Push("小明");
//Pop把元素出栈,栈中就没有这个元素了
// string s1 = s.Pop ();
// Console.WriteLine (s1);
// string s2 = s.Pop ();
// Console.WriteLine (s2);
// string s3= s.Pop ();
// Console.WriteLine (s3);
Queue<string> q = new Queue<string> ();
q.Clear ();
int count = q.Count;
bool b = q.Contains ("老王");
//向队列中添加元素
q.Enqueue("老王");
q.Enqueue("老张");
q.Enqueue("小明");
//获取队列中元素
string s1=q.Dequeue();
Console.WriteLine (s1);
string s2 = q.Dequeue ();
Console.WriteLine (s2);
string s3 = q.Dequeue ();
Console.WriteLine (s3);
}
}
}
栈遵循后进先出的原则
队列遵循先进后出的原则
栈和队列根据需要容量自动增加
栈和队列都允许重复元素
推荐视频讲师博客:http://11165165.blog.51cto.com/
using System;
using System.Collections.Generic;
namespace Lesson_25
{
class MainClass
{
public static void Main (string[] args)
{
Stack<string> s = new Stack<string> ();
int count = s.Count;
s.Clear ();
bool b = s.Contains ("老王");
//把元素入栈
s.Push("老王");
s.Push("老张");
s.Push("小明");
//Pop把元素出栈,栈中就没有这个元素了
string s1 = s.Pop ();
Console.WriteLine (s1);
string s2 = s.Pop ();
Console.WriteLine (s2);
string s3= s.Pop ();
Console.WriteLine (s3);
}
}
}
using System;
using System.Collections.Generic;
namespace Lesson_25
{
class MainClass
{
public static void Main (string[] args)
{
// Stack<string> s = new Stack<string> ();
// int count = s.Count;
// s.Clear ();
// bool b = s.Contains ("老王");
//把元素入栈
// s.Push("老王");
// s.Push("老张");
// s.Push("小明");
//Pop把元素出栈,栈中就没有这个元素了
// string s1 = s.Pop ();
// Console.WriteLine (s1);
// string s2 = s.Pop ();
// Console.WriteLine (s2);
// string s3= s.Pop ();
// Console.WriteLine (s3);
Queue<string> q = new Queue<string> ();
q.Clear ();
int count = q.Count;
bool b = q.Contains ("老王");
//向队列中添加元素
q.Enqueue("老王");
q.Enqueue("老张");
q.Enqueue("小明");
//获取队列中元素
string s1=q.Dequeue();
Console.WriteLine (s1);
string s2 = q.Dequeue ();
Console.WriteLine (s2);
string s3 = q.Dequeue ();
Console.WriteLine (s3);
}
}
}
相关文章推荐
- 蓝鸥Unity开发基础二——课时13 析构方法
- 蓝鸥Unity开发基础二——课时17 静态类
- 蓝鸥Unity开发基础二——课时11 方法重载
- 蓝鸥Unity开发基础二——课时16 抽象类
- 蓝鸥Unity开发基础二——课时19 虚方法
- 蓝鸥Unity开发基础二——课时2 结构体
- 蓝鸥Unity开发基础——关系运算和逻辑运算学习笔记
- 蓝鸥Unity开发基础——关系运算和逻辑运算学习笔记
- iOS开发零基础教程之AFNetWorking POST 队列请求
- 精通JavaScript开发课时11(DOM基础)笔记
- iPhone开发教程 UI基础课程(58课时)
- 蓝鸥Unity开发基础——结构体
- 蓝鸥Unity开发基础——运算符和表达式学习笔记
- iPhone开发教程 UI基础课程(58课时)
- 蓝鸥Unity开发基础—— 一维数组学习笔记
- 蓝鸥Unity开发基础—— 一维数组学习笔记
- 蓝鸥Unity开发基础——if语句学习笔记
- iPhone开发教程 UI基础课程(58课时)
- (5)iPhone开发基础 - 消息队列
- IOS开发基础知识--碎片25