Advertisement
Guest User

Untitled

a guest
May 21st, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. //Node Queue SLL
  2. class Node{
  3.     int x, y;
  4.     Node next;
  5.  
  6.     public Node(int x, int y){
  7.         this.x = x;
  8.         this.y = y;
  9.     }
  10. }
  11. //Clase Queue
  12. class Queue{
  13.     Node front,rear;
  14.  
  15.     public Queue(){
  16.         this.front = null;
  17.         this.rear = null;
  18.     }
  19.  
  20.     boolean isEmpty(){
  21.         return front==null;
  22.     }
  23.  
  24.     void enqueue(int keyX, int KeyY){
  25.         Node temp = new Node(keyX,KeyY);
  26.        
  27.         if(this.rear == null){
  28.             this.front = this.rear = temp;
  29.         }
  30.         this.rear.next=temp;
  31.         this.rear=temp;
  32.     }
  33.  
  34.     Node dequeue(){
  35.         if (this.front == null)
  36.            return null;
  37.        
  38.         Node temp = this.front;
  39.         this.front = this.front.next;
  40.  
  41.         if (this.front == null){
  42.             this.rear = null;
  43.         }
  44.            
  45.         return temp;
  46.     }
  47.  
  48.     int[] front(){
  49.         if(isEmpty()){
  50.             System.out.println("Empty Queue");
  51.         }
  52.         int []coor = {front.x,front.y};
  53.         return coor;
  54.     }
  55.  
  56.     int[] rear(){
  57.         if(this.rear==null){
  58.             System.out.println("Empty Queue");
  59.         }
  60.         int[] coor = {rear.x,rear.y};
  61.         return coor;
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement