这种作业不难.看这个周末有没有时间,不去SHOPPING就做.

解决方案 »

  1.   

    helpall大哥,你是我的救命恩人!!!shopping就下次吧,小弟这次过不了就要补考了。俗话说救人一命,那个胜造七级什么什么的人命关天哪!!分要多少随便说,全给你!!呵呵。
      

  2.   

    这样吧. 你选择一下:
      1. 有三个函数,我做一个,你做两个,今晚交货.你指定我做哪个.
      2. 如果不shopping的话,三个函数全部我做,星期天交货. 如果shopping的话,一个都不做.public class Queue {
       private Semaphore sem = new Semaphore(1);
       private Object[] ar;
       private int size;   public Queue(int size) {
          this.size = size;
          ar = new Object[size];
       }   public void q_put(Object o) {
       }
       public Object q_get() {
         return new Object();
       }
       public int q_size() {
       }
       public static void main(String[] args) {
          // testing
       }
    }
      

  3.   


    public class Queue {   private Semaphore sem = new Semaphore(1);
       private Object[] ar;
       private int SIZE;
       private int index_begin = 0;
       private int index_end = 0;   public Queue(int size) {
          SIZE = size;
          ar = new Object[SIZE];
       }   public void q_put(Object o) {
          if( SIZE == q_size()) {
             try{
                sem.sem_wait();
             }catch(InterruptedException e){
             }
          }
          System.out.println("PUT:"+o);
          index_end = (index_end+1) % SIZE;
          ar[index_end] = o;
          System.out.println("Size after put:"+ q_size() );
          sem.sem_post();
       }
       
       public Object q_get() {
          return new Object();
       }
       public int q_size() {
          return (index_end + SIZE - index_begin) % SIZE;
       }   public static void main(String[] args) {
          // testing
          Queue queue1 = new Queue(1);
       }
    }