public Stacks(int K, int N)
for(int i=0; i < next.Length; i++)
next[next.Length-1] = -1;
for (int i = 0; i < top.Length; ++i)
public void Push(int stackIndex, int element)
throw new ApplicationException("Container is full");
next[i] = top[stackIndex];
public int Pop(int stackIndex)
int stackTop = top[stackIndex];
throw new ApplicationException(string.Format("Stack{0} underflow", stackIndex));
int v = content[stackTop];
top[stackIndex] = next[stackTop];
next[stackTop] = nextFree;
public bool IsEmpty(int stackIndex)
return top[stackIndex] == -1;
public static void Main()
Stacks s = new Stacks(3, 15);
private static void TestPush(Stacks s, int index, int v)
Console.WriteLine("Push{0}({1})", index, v);
private static void TestPop(Stacks s, int index)
Console.WriteLine("Pop{0} -> {1}", index, v);