using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class 实现栈 : MonoBehaviour {
class MyStack
{
class StackData
{
public StackData nextItem;
public object topData;
public StackData(StackData next,object data)
{
this.nextItem = next;
this.topData = data;
}
}
StackData top;
public void Push(object data)
{
top = new StackData(top,data);
}
public object Pop()
{
object rs1 = top.topData;
top = top.nextItem;
return rs1;
}
}
void Start()
{
MyStack ms = new MyStack();
ms.Push(1);
ms.Push(2);
ms.Push(3);
Debug.Log(ms.Pop());//3
Debug.Log(ms.Pop());//2
Debug.Log(ms.Pop());//1
}
}
07-12
07-12
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交