蓝鸥Unity开发基础二——课时25 栈和队列
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了蓝鸥Unity开发基础二——课时25 栈和队列,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1522字,纯文字阅读大概需要3分钟。
内容图文
蓝鸥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://11131960.blog.51cto.com/11121960/1850591
内容总结
以上是互联网集市为您收集整理的蓝鸥Unity开发基础二——课时25 栈和队列全部内容,希望文章能够帮你解决蓝鸥Unity开发基础二——课时25 栈和队列所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。