public void Push(T NewStack) { //If is empty if (!IsNotEmpty) { //First time HasPushed IsNotEmpty = true; //Create temp Temp = new mstack <T>(); //Assign NewStack to temp Temp.Data = NewStack; } else { //Assign Next Next = new mstack <T>(); //Make Next point to temp Next.Next = Temp; //Make temp point to next Temp = Next; //Asign Temp.Data to NewStack Temp.Data = NewStack; //Make next not point to next Next = null; } }
public IEnumerator <T> GetEnumerator() { mstack <T> mpointer = Temp; while (mpointer != null) { yield return(mpointer.Data); mpointer = mpointer.Next; } }
public T Pop() { //If the stack isnt empty if (IsNotEmpty) { //Create a placeholder for the data T PlaceHolder = Temp.Data; //Remove it from the stack Temp = Temp.Next; //if it is empty, IsEmpty = false if (Temp == null) { IsNotEmpty = false; } return(PlaceHolder); } else { return(Data); } }