Created
February 18, 2013 06:02
-
-
Save apremalal/4975374 to your computer and use it in GitHub Desktop.
An implementation of a Stack in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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