queue.java
contents ::
  app.java
  graph.java
  node.java
  queue.java


/* The queue structure 
struct queue_c {
  int *the_q;
  int front;
  int end;
  int size;
  };*/
//static int size = 0;
class queue {
    int []the_q;
    int front;
    int end;
    int size;
    
    /* creates a new queue */
    queue(int size){
         the_q = new int[size];
         this.size=size;
         front=0;
         end=0;
    }

    /*
      returns the size of the queue 
      this should be the number of items
      actually in the queue
    */

    boolean queue_empty(){
         return (end == front);
    }

    /*
      inserts an item onto the queue
      if there is room returns 1 for "all good"
      if the queue is full returns 0 
      for "all is not so good"
    */
    void queue_enqueue(int i){
         if(end+1!=front){
             the_q[end%size]=i;
             end++;
             // return 1;
         } else {
            System.out.print("Sorry queue full\n");
            System.exit(-1);
         }
    }

    /*
      returns the item at the front of the queue
      if there is an item to return it returns it,
      if there is not then it returns -1
      ********************************************
      returning -1 is ok for the implementation of the
      graph but if we want to put something onto the
      stack that could possibly return -1, then we will
      have to exit the program if there is nothing on
      the queue to return, else make sure that error
      checking is preformed before this is called.
    */
    int queue_dequeue(){
         if(!queue_empty()){
             int value = the_q[front%size];
             front++;
             return value;
         } else {
             System.out.print("Sorry queue empty\n");
             return -1; /* I don't really feel -1 is satisfacory value to return */
         }
    }
}

James Little