public class Stack {
private boolean empty,full;
private int pos;
private int max_data=100;
private int item [max_data];
public Stack(){
full=false;
empty=true;
pos=0;
}
public boolean isFull(){
return(full);
}
public boolean isEmpty(){
return(empty);
}
public void push(int data){
if (!isFull()){
item [pos++] = data;
empty = false;
if (pos==max_data){
full=true;
}
}
else {
System.out.print("Stack is Full");
}
return;
}
public int pop(){
int x;
if (!isEmpty()){
x = item [--pos];
if(pos==0){
empty=true;
}
}
else{
System.out.print("Stack is Empty");
}
return(x);
}
}
Tidak ada komentar:
Posting Komentar