示例#1
0
 public int peek(stacks s)
 {
     if (!isEmpty(s))
     {
         IndexArray idx = idxStack[(int)s];
         return(array[idx.Current - 1]);
     }
     else
     {
         throw new EmptyStackException();
     }
 }
示例#2
0
            public void push(stacks s, int el)
            {
                IndexArray idx = idxStack[(int)s];

                if (!isFull(s))
                {
                    array[idx.Current] = el;
                    idx.Current++;
                }
                else
                {
                    throw new FullStackException();
                }
            }
示例#3
0
            public int pop(stacks s)
            {
                IndexArray idx = idxStack[(int)s];

                if (!isEmpty(s))
                {
                    int result = array[idx.Current - 1];
                    array[idx.Current] = 0;
                    idx.Current--;
                    return(result);
                }
                else
                {
                    throw new EmptyStackException();
                }
            }
示例#4
0
            public bool isFull(stacks s)
            {
                IndexArray idx = idxStack[(int)s];

                return(idx.Current > idx.Last);
            }
示例#5
0
            public bool isEmpty(stacks s)
            {
                IndexArray idx = idxStack[(int)s];

                return(idx.Current.Equals(idx.First));
            }