Skip to content

Instantly share code, notes, and snippets.

@khatchad
Created December 21, 2015 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khatchad/9df9b9af509012385834 to your computer and use it in GitHub Desktop.
Save khatchad/9df9b9af509012385834 to your computer and use it in GitHub Desktop.
public class IntStack {
/**
* The maximum size of this stack.
*/
private static final int MAX_SIZE = 100;
/**
* The values stored in this stack. It should be initially empty.
*/
private int[] values;
/**
* The number of valid elements in this stack. It should be initially 0 since we start with an empty stack.
*/
private int nvalid;
/**
* Creates an initially empty stack.
*/
public IntStack() {
}
/**
* Pushes element onto this stack only if there is room.
*
* @param element The element to push onto this stack.
*/
public void push(int element) {
}
/**
* Pops the last value pushed onto this stack. Has no affect if this stack
* is empty.
*/
public void pop() {
}
/**
* Returns the value at the top of this stack if the stack is non−empty,
* otherwise, throws an exception.
*
* @return The element at the top of the stack if it exists.
* @throws IllegalStateException If the stack is empty.
*/
public int top() {
return 0; //TODO.
}
/**
* Returns true if this stack is empty and false otherwise.
*
* @return True if this stack is empty and false otherwise.
*/
public boolean isEmpty() {
return false; //TODO.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment