Queue
Queue
Queue
queue[++rear] = data;
}
void dequeue() {
if (front > rear) {
System.out.println("Queue is empty");
return;
}
rear--;
}
----------------------------------------------------------------------------
linked list implementation of queue
boolean isEmpty() {
return front == null && rear == null;
}
// If queue is empty, the new node is both the front and rear
if (rear == null) {
front = rear = new_node;
return;
}
rear.next = new_node;
rear = new_node;
}
void dequeue() {
if (isEmpty()) {
System.out.println("Queue Underflow");
return;
}
// Update i to parent of i
i = parent(i);
}
}
// Left Child
int l = leftChild(i);
// Right Child
int r = rightChild(i);
// Function to insert a
// new element in
// the Binary Heap
static void insert(int p)
{
size = size + 1;
H[size] = p;
// Shift Up to maintain
// heap property
shiftUp(size);
}
// Function to extract
// the element with
// maximum priority
static int extractMax()
{
int result = H[0];
if (p > oldp)
{
shiftUp(i);
}
else
{
shiftDown(i);
}
}
// Driver Code
public static void main(String[] args)
{
/* 45
/ \
31 14
/ \ / \
13 20 7 11
/ \
12 7
Create a priority queue shown in
example in a binary max heap form.
Queue will be represented in the
form of array as:
45 31 14 13 20 7 11 12 7 */
int i = 0;
System.out.print("\n");
System.out.print("\n");
System.out.print("\n");