Skip to content

Instantly share code, notes, and snippets.

@apremalal
Created February 18, 2013 06:02
Show Gist options
  • Save apremalal/4975374 to your computer and use it in GitHub Desktop.
Save apremalal/4975374 to your computer and use it in GitHub Desktop.
An implementation of a Stack in java
public class Stack {
int s[] = new int[100];
int top = -1;
boolean isEmpty(Stack s) {
if (s.top < 0) {
return true;
} else
return false;
}
void push(Stack s, int x) {
s.top = s.top + 1;
s.s[s.top] = x;
}
int pop(Stack s, int x) {
if (s.isEmpty(s)) {
System.out.println("Stack is empty");
return -1;
} else {
s.top = s.top - 1;
return s.s[s.top + 1];.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment