unity3D-游戏/AR/VR在线就业班 蓝鸥C#入门栈和队列学习笔记

unity3D-游戏/AR/VR在线就业班 蓝鸥C#入门栈和队列学习笔记

一、栈和队列

栈遵循后进先出的原则

队列遵循先进后出的原则

栈和队列根据需要容量自动增加

栈和队列都允许重复元素

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);
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值