Created
March 3, 2019 03:31
-
-
Save graphoarty/94d2be78c6ac0ba07a62111f0a6b3187 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 { | |
//initialize | |
//enqueue | |
//dequeue | |
//empty | |
//adjustQueue | |
static final int max = 10; | |
int[] queueArray = new int[max]; | |
int top; | |
int bottom; | |
int dequeued; | |
void initialize(){ | |
top = 0; | |
bottom = 0; | |
} | |
void enqueue(int num){ | |
if(top < max) | |
queueArray[top++] = num; | |
else | |
System.out.println(num + " cannot be queued!"); | |
} | |
int dequeue(){ | |
dequeued = queueArray[bottom]; | |
adjustQueue(); | |
top--; | |
return dequeued; | |
} | |
void adjustQueue() { | |
for(int i = 0; i < max-1 ; i++){ | |
queueArray[i] = queueArray[i+1]; | |
} | |
} | |
void isEmpty(){ | |
if(top == 0){ | |
System.out.println("The queue is empty!"); | |
}else if(top == max){ | |
System.out.println("The queue is full!"); | |
}else{ | |
System.out.println("The queue is not empty!"); | |
} | |
} | |
void printQueue(){ | |
if(top>0){ | |
System.out.println("The formed queue is!"); | |
for(int i = 0; i < top; i++){ | |
System.out.print(" | " + queueArray[i]); | |
} | |
System.out.println(" | "); | |
}else{ | |
System.out.println("The queue is empty!"); | |
} | |
} | |
} | |
public class QueueImplementation { | |
public static void main(String[] args){ | |
Queue queue = new Queue(); | |
//queue.enqueue(num); | |
//queue.dequeue(); | |
//queue.printQueue(num); | |
//queue.isEmpty(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment