Answer the question
In order to leave comments, you need to log in
I wrote the code and I need to add the PriorityQueue class, but I don't know if I wrote the class correctly?
Please help, I wrote the code and I need to add the PriorityQueue class, but I don’t know if I wrote the class correctly - please tell me.
Here is my code that I wrote.
package com.company;
import java.util.*;
public class Main {
public static class PriorityQueueExample {
public static void main(String[] args) {
PriorityQueue<Integer> PQueue = new PriorityQueue<>();
PriorityQueue<String> PQueue2 = new PriorityQueue<>();
PQueue2.add("BMW");
PQueue.add(25);
PQueue2.add("Mazda");
PQueue.add(35);
PQueue2.add("Tesla");
PQueue.remove(10);
PQueue2.remove("Tesla");
Iterator iterator = PQueue.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next() + " ");
}
Iterator iterator2 = PQueue2.iterator();
while (iterator2.hasNext()) {
System.out.println(iterator2.next() + " ");
}
System.out.println("Повертає - " + PQueue + PQueue2);
System.out.println("Видаляэ - " + PQueue.poll() + "," + PQueue2.poll());
System.out.println("Фінальна стадія" + PQueue + PQueue2);
Integer element = PQueue.peek();
String element2 = PQueue2.peek();
System.out.println("Доступні елементи- " + element + element2);
System.out.println("Колекція-" + PQueue + PQueue2);
System.out.println(" ");
System.out.println("Чи колекція є пуста? " + PQueue.isEmpty() + "," + PQueue2.isEmpty());
System.out.println("Розмір черги- " + PQueue.size() + " && " + PQueue2.size());
System.out.println(" ");
System.out.println("Чи є констаната Mazda і 35? " + PQueue.contains(35) + "," + PQueue2.contains("Mazda"));
System.out.println("Чи є констаната Nissan і 55? " + PQueue.contains(55) + "," + PQueue2.contains("Nissan"));
}
}
}
Answer the question
In order to leave comments, you need to log in
Good afternoon!
but I don't know if I wrote the class correctly - tell me please.
public class Main {
public static class PriorityQueueExample {
public class PriorityQueueExample {
PriorityQueue<Integer> PQueue = new PriorityQueue<>();
PQueue2.add("BMW");
PQueue.add(25);
PQueue2.add("Mazda");
PQueue.add(35);
PQueue2.add("Tesla");
PQueue.remove(10);
PQueue2.remove("Tesla");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question