Java Stack

package Stack;

class Stack_class {
     int [] stack_ref;
     int max_len, top_index;

    public Stack_class() { // A Constructor
        stack_ref = new int [10];
        max_len = 9;
        top_index = -1;
    }
    public void push(int number) {
        if (top_index == max_len)
        System.out.println("Error in push-stack is full");
        else {
          System.out.println("push:"+number);       
          stack_ref[++top_index] = number;
        }
    }
    public void pop() {
        if (top_index == -1)
        System.out.println("Error in pop-stack is empty");
        else {
          System.out.println("pop:"+stack_ref[top_index]); 
          --top_index;}
        }
  }

public class stacks {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub

  Stack_class st=new Stack_class();

  st.push(5);
  st.push(6);
  st.push(7);
  st.push(8);
  st.push(9);
  st.push(31);
  st.push(34);
  st.push(232);
  st.push(4);
  st.push(7);
  st.push(22);
  st.pop();
  st.pop();
  st.pop();
  st.pop();
  st.pop();
  st.pop();
  st.pop();
  st.push(312312);
  st.pop();
  st.pop();
  st.pop();
  st.pop();
  
  }

}
/////////////////////////////////////////////////////////////////

package aa;

class Stacks{

 int bottom;
 int Stack[];
 int remain;

 public Stacks(){
 
 
  Stack = new int [10];
  bottom = -1;
  remain= 9;
   
 }

 void push_st(int pu){
 
  if(remain==0)System.out.println("Err. Stack is Full");
 
  else {
    System.out.println("push:"+pu);
    Stack[++bottom]= pu;
    remain--;
  }
   
 
 }

 void pop_st(){
  if(bottom==-1) System.out.println("Err. Stack is Empty");
 
  else {
    System.out.println("pop:"+Stack[bottom]);
    bottom--;
    remain++;
  }
 }


}

public class gemi {

  /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
 
  Stacks stt = new Stacks();
 
  stt.push_st(5);
  stt.push_st(6);
  stt.push_st(7);
  stt.push_st(8);
  stt.push_st(9);
  stt.push_st(10);
  stt.push_st(11);
  stt.push_st(12);
  stt.push_st(13);
  stt.push_st(14);
  stt.push_st(15);
 
  stt.pop_st();
  stt.pop_st();
  stt.pop_st();
  stt.pop_st();
  stt.pop_st();
  stt.pop_st();
  stt.pop_st();
  stt.pop_st();
  stt.pop_st();
  stt.pop_st();
 
 
 }

}

by muzie | 2007/03/26 19:53 | STUDY | 트랙백 | 덧글(0)

트랙백 주소 : http://muzie.egloos.com/tb/3075277
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]

:         :

:

비공개 덧글

◀ 이전 페이지          다음 페이지 ▶