Today, I have been busy, under my heart, I finally discovered the problem of the program.
The problem is in the class of an analog stack, the program is as follows:
Using system.collections; using system.text;
Namespace Arithmetic {public class stack {/// ///// summary> private arraylist mystack; /// /// initialization /// /////////////////// summary> Public Stack () {Mystack = new arraylist ();
/// /// 入 栈 /// summary> /// into the stack object param> public void push (Object O) {mystack.add (o) }
/// /// out of the stack /// summary> /// Return Object returns> public object pop () {int count = MyStack.count - 1; if (count <0 ) {Throw new exception;} Object o = mystack [count]; MyStack.remove (o); // The problem is Return O;}
/// /// Judgment stack empty /// summary> /// BOOL value return> public bool iSempty () {return (MyStack.count == 0);}
/// /// Return Stack Top Object /// Summary> /// Return Stack Top Object Returns> Public Object TopItem () {INT Count = MyStack.count - 1; IF (count <0) {throw new exception ("stack empty");} Object o = mystack [count]; returno}}}
When I use this class analog stack, there is no mistake at other places, it is removed in the stack, which is remove (O), this method is to delete the first matching item, so when there is the same item in the stack, The stack will be wrong and change it to:
MyStack.removeat (count) is OK.