您的位置:首页 > 移动开发 > Unity3D

蓝鸥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);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  3D Unity 蓝鸥