Created
May 1, 2016 06:03
-
-
Save malikburhan/398e8edd0e553e9a2fe844a437107f68 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Queue //stating class | |
{ | |
int front , rear ,e, queSize , queArr[]; // initialized | |
Queue(int size) //constructor | |
{ | |
this.queSize=size; | |
this.queArr=new int[queSize]; | |
this.front=-1; | |
this.rear=-1; | |
} | |
public void EnQueue(int e) //method for input data in Queue | |
{ | |
if (front==-1) //check Queue is empety or not | |
front=0; // if yes then initialized it with zero | |
if(rear==(queSize-1)) // check Queue is full or not | |
System.out.println("overflow"); // if full the over flow | |
else | |
rear=rear+1; | |
queArr[rear]=e; // add data in rear of Queue | |
} | |
public int DeQueue() // method of delete data from Queue | |
{ | |
if((front==-1) || (front>rear)) // check Queue either empety or "rear is greater then front" | |
System.out.println("underflow"); //if yes then show underflow | |
else | |
e =queArr[front]; // delete data from Queue | |
front=front+1; | |
return e; // value return to method | |
} | |
public void display() // method of display the Queue | |
{ | |
System.out.println("The data in the Queue"); | |
for(int i=front; i<=rear; i++) // start loop from front to rear | |
System.out.println(queArr[i]); | |
} | |
public static void main(String args[]) | |
{ | |
Queue obj=new Queue(5); // you will change the size of array | |
obj.EnQueue(1111); //input data | |
obj.EnQueue(2222); //input data | |
obj.EnQueue(3333); //input data | |
obj.EnQueue(4444); //input data | |
obj.EnQueue(5555); //input data | |
obj.display(); | |
obj.DeQueue(); //delete data | |
obj.DeQueue(); //delete data | |
obj.display(); | |
} | |
} // end of Queue class | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment