answersLogoWhite

0

import java.util.*;

import java.io.*;

class PriorityQueue

{

int Q[];

int front,rear;

public PriorityQueue(int size)

{

rear=front=-1;

Q=new int[size];

}

public void offer(int val)

{

if((Q.length-1)>rear)

{

Q[++rear]=val;

System.out.println("offer elements in queue is"+ val);

}

else

{

front=rear=-1;

System.out.println("queue is overflow");

}

}

public void poll()

{

if(front==rear)

{

System.out.println("queue is empty");

}

else

{

System.out.println("poll element is"+ Q[++front]);

}

}

}

public class QueueDemo

{

public static void main(String[] args)

{

PriorityQueue Qu=new PriorityQueue(5);

Qu.offer(30);

Qu.offer(40);

Qu.offer(50);

Qu.offer(60);

Qu.poll();

Qu.poll();

}

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

How do you write a Java program to implement weighted queue using circular doubly linked list?

Add weights to the elements of the queue and use an algorithm to sort the queue every time an element is added.


What are the requirements to download a java arraylist?

The requirements to download a java arraylist are a pc with java software installed. A java arraylist is used to store a group of elements in a specific order.


What type of platform does Arraylist Java run on?

Arraylist Java runs on Oracle which is a relational data management database produced by the Oracle Corporation. Arraylist Java has been part of the Java framework ever since Java 5.


How do you Implement a Stack using an ArrayList in java?

Just add the elements to the end of the ArrayList, and take them out from the end of the ArrayList. Use the .add() method to add an element to the end; use the .size() method to find out how many elements it has (so you can access the last element), and use the .remove() method to eliminate this last element.


How can you sort an arraylist of strings?

You can sort an ArrayList by using the sort method of the Collecions class (java.util.Collections). Assuming you have an ArrayList called foo: Collections.sort(foo);


Where can Java Queue be downloaded?

A 'queue' is a particular kind of data structure that Java is capable of working with. There are no products called "Java Queue" and is thus not something one can download.


Where can one find out how to implement threads using Java?

You can find out how to implement threads using Java through Stacker Overflow, Java Script Source, Java Code Geeks, Free Programming Resources and other websites. There are also tutorials on college sites as well as Youtube.


Write a java program to implement stack in java?

You would need an array to store the actual stack. Better use an ArrayList or some other structure that you can redimension. You'll also need a variable to point to the "top of stack" - the last element added, which is the first element to be taken away.


Can you provide a solution to the diamond-square algorithm using Java and recursion?

Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.


What is subclasses in java?

Subclasses are classes that inherit from parent classes. i.e. ArrayList is a subclass of List.


How you can store a class variables in array list?

An (non generic) arrayList in java can save any type of object (in this case your class variable) in this straightforward way: MyClass myClassVar = new MyClass(); ArrayList myArrayList = new ArrayList(); myArrayList.add(myClassVar);


What are advantages of an arraylist?

ArrayList Features In Java Index based – Elements can be randomly accessed using index . Arraylist Index start with ‘0’. Ordered – Elements maintain insertion ordered . Dynamic resizing – increase size dynamically when more elements needs to be added than it’ current size. Non synchronized – is not synchronized, by default.. Duplicates allowed – We can add duplicate elements . null value – Arraylist can store null values.