public class Stack {
protected int m_size;
protected int m_maxsize;
protected Object[] m_stack;
public Stack() {
m_size = 0;
m_maxsize = 100;
m_stack = new Object[m_maxsize];
}
public void Push(Object element) {
if (m_size >= m_maxsize)
throw new OutOfMemoryException();
m_stack[m_size++] = element;
}
public Object Pop() {
if (m_size == 0)
throw new NullReferenceException();
return m_stack[--m_size];
}
public int Size {
get { return m_size; }
}
}
Previous slide | Next slide | Back to first slide | View graphic version |