* A special sequence table for a first-in-last-out (last-in-first-out) object collection
* Stack
* Last-in-first-out, the last inserted object is at the top of the stack
*
* Stack method
* Push
* Pop * Pop Stack pop
* Peek View the top of the stack
* Clear clear the stack
* Contains whether it contains
* Count the number of elements in the stack
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading;
public class Test : MonoBehaviour
{
/*
* 先进后出 (后进先出)的对象集合 特殊的顺序表
* 栈(Stack)
* 后进先出,最后插入的对象位于栈的顶端
*
* Stack的方法
* Push 压栈 进栈 入栈
* Pop 出栈 弹栈
* Peek 查看栈顶
* Clear 清空堆栈
* Contains 是否包含
* Count 栈内元素的个数
*/
private void Start()
{
StackTest();
}
public static void StackTest()
{
Stack stack = new Stack();
stack.Push("第一颗子弹");
stack.Push("第二颗子弹");
stack.Push("第三颗子弹");
stack.Push("第四颗子弹");
stack.Push("第五颗子弹");
while (stack.Count != 0)
{
Debug.Log("击发" + stack.Pop());
Thread.Sleep(2000);
}
}
}