Skip to content

Instantly share code, notes, and snippets.

@yukeehan
Created March 2, 2018 19:56
Show Gist options
  • Save yukeehan/63687d4ff00586493ad30775c07eeeaf to your computer and use it in GitHub Desktop.
Save yukeehan/63687d4ff00586493ad30775c07eeeaf to your computer and use it in GitHub Desktop.
class Stack1{
private char q[];
private int tos;
int length;
Stack1(int size){
q = new char [size];
tos = 0;
length = size;
}
void push(char ch) {
if(tos == q.length) {
System.out.println("full");
return;
}
q[tos] = ch;
tos++;
}
char pop() {
if(tos == 0) {
System.out.println("empty");
return (char) 0;
}
tos--;
return q[tos];
}
}
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Stack1 q = new Stack1(10);
char ch;
for(int i=0; i<(q.length);i++) {
q.push((char)('A'+i));
}
for(int i=0; i<(q.length);i++) {
ch = q.pop();
if(ch != (char) 0) System.out.print(ch);
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment