public int Pop(StackOption stackOption) { if (stackOption == StackOption.One && this.stackOneTop == -1) { return(-1); } if (stackOption == StackOption.Two && this.stackTwoTop == this.stackArray.Length) { return(-1); } int result = -1; if (stackOption == StackOption.One) { result = this.stackArray[this.stackOneTop]; this.stackArray[this.stackOneTop] = 0; this.stackOneTop--; } if (stackOption == StackOption.Two) { result = this.stackArray[this.stackTwoTop]; this.stackArray[this.stackTwoTop] = 0; this.stackTwoTop++; } return(result); }
public bool Push(int value, StackOption stackOption) { // deduct one from stack 2 top, as you cannot have both pointing to same index as it may overwrite the value. if (stackOneTop == stackTwoTop - 1) { // stack is full return(false); } if (stackOption == StackOption.One) { this.stackOneTop += 1; this.stackArray[this.stackOneTop] = value; } if (stackOption == StackOption.Two) { this.stackTwoTop -= 1; this.stackArray[this.stackTwoTop] = value; } return(true); }