The principle of the stack is advanced after the out. Queues are FIFO. Stack like take the elevator, the last first out. Queues are queued.
Implementation code:
public class Mystack<t> {private int top; Private t[] Stkarr; private int maxSize; <summary>///= stack top index///</summary> public int Top {set {top = VA Lue } get {return top;} } public t[] Stkarr {set {Stkarr = value;} get {return stkarr;} } public int MaxSize {get {return MaxSize;} set {if (value < 0) {throw new Exception ("MaxSize is D 0! "); } else {maxSize = value; }}} public mystack (int maxSize) {this. MaxSize = MaxSize; This. Stkarr = new T[maxsize]; Top = 0; }///<summary>///Outbound//</summary> public T pop () {if (IsNull ()) {throw new Exception ("Stack is empty!"); } else {return stkarr[--top]; }}///<summary>/////</summary> public void Pash (T value) { if (Isfull ()) {throw new Exception ("Stack full!"); } else {stkarr[top++] = value; }}///<summary>//judgment stack is full///</summary>//<returns></return S> public bool Isfull () {return (Top = = MaxSize); }//<summary>//judgment stack is empty///</summary>//<returns></returns> public bool IsNull () {return (Top = = 0); }//<summary>//return stack size///</summary>//<returns></returns> public int GetmaxsiZe () {return MaxSize; }///<summary>//traverse stacks///</summary>//<returns></returns> Public IEnumerable getenumerable () {for (int i = 0; i < MaxSize; i++) {Yi Eld return stkarr[i]; } } }
C # Custom Stacks