Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Node Queue SLL
- class Node{
- int x, y;
- Node next;
- public Node(int x, int y){
- this.x = x;
- this.y = y;
- }
- }
- //Clase Queue
- class Queue{
- Node front,rear;
- public Queue(){
- this.front = null;
- this.rear = null;
- }
- boolean isEmpty(){
- return front==null;
- }
- void enqueue(int keyX, int KeyY){
- Node temp = new Node(keyX,KeyY);
- if(this.rear == null){
- this.front = this.rear = temp;
- }
- this.rear.next=temp;
- this.rear=temp;
- }
- Node dequeue(){
- if (this.front == null)
- return null;
- Node temp = this.front;
- this.front = this.front.next;
- if (this.front == null){
- this.rear = null;
- }
- return temp;
- }
- int[] front(){
- if(isEmpty()){
- System.out.println("Empty Queue");
- }
- int []coor = {front.x,front.y};
- return coor;
- }
- int[] rear(){
- if(this.rear==null){
- System.out.println("Empty Queue");
- }
- int[] coor = {rear.x,rear.y};
- return coor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement