Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphoarty/94d2be78c6ac0ba07a62111f0a6b3187 to your computer and use it in GitHub Desktop.
Save graphoarty/94d2be78c6ac0ba07a62111f0a6b3187 to your computer and use it in GitHub Desktop.
public class Queue {
//initialize
//enqueue
//dequeue
//empty
//print
//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