- VR topik
- Vezeték nélküli fülhallgatók
- Fejhallgató erősítő és DAC topik
- AMD Ryzen 9 / 7 / 5 10***(X) "Zen 6" (AM5)
- AMD Ryzen 9 / 7 / 5 9***(X) "Zen 5" (AM5)
- Autós kamerák
- Milyen egeret válasszak?
- Házimozi belépő szinten
- LCD, plazma és projektoros TV-k hibái
- NVIDIA GeForce RTX 5070 / 5070 Ti (GB205 / 203)
Új hozzászólás Aktív témák
-
#74220800
törölt tag
Ja maradt az arraylist, az a legkézenfekvőbb. De valamiért, a leadó system testje vmiert ezt a hibát írja ki:
Removed two elements but the second one had a lower priority than the first one! Amit nem értek. Amugy itt van a programom(class nevet most atneveztem):
import java.util.ArrayList;
public class MyPriorityQueue<T extends Comparable<T>> {
private ArrayList<T> queue;
private int maxElements;
public MyPriorityQueue(int maxElements){
this.maxElements = maxElements;
queue = new ArrayList<T>();
}
public void add(T e) throws IllegalStateException{
if( size() == maxElements)
throw new IllegalStateException("The queue is already full!");
queue.add(e);
int i = size()-1 ;
T help;
while ( i > 0 && ( queue.get( parent(i) ).compareTo( queue.get(i) ) ) > 0 ){
help = queue.get(i);
queue.set(i,queue.get( parent(i) ));
queue.set(parent(i), help);
i = parent(i);
}
}
public T pop() throws IllegalStateException{
if(queue.isEmpty())
throw new IllegalStateException("The queue is empty!");
T min = queue.get(0);
queue.remove(0);
minheapify(0);
return min;
}
public int size(){
return queue.size();
}
public int parent(int i){
return (i - 1) / 2;
}
public void minheapify(int i){
int l = i*2+1;
int r = l+1;
int min;
T help;
if (l <= size()-1 && ( queue.get(l).compareTo( queue.get(i) ) ) < 0 )
min = l;
else
min = i;
if (r <= size()-1 && ( queue.get(r).compareTo( queue.get(min) ) ) < 0)
min = r;
if (min != i){
help = queue.get(i);
queue.set(i,queue.get(min));
queue.set(min, help);
minheapify(min);
}
}
public void display(){
for(int i = 0; i < queue.size(); i++) {
System.out.print(queue.get(i) + " ");
}
}
}
Új hozzászólás Aktív témák
A topicot kiemeltem. Valaki nem akar egy nyitó hsz-t írni?:))
- 15" Workstation: Lenovo Thinkpad P1 gen2 // P52s // P15 gen1 // FHD, 4K oled touch
- BESZÁMÍTÁS! Gigabyte B760M i5 14400F 16GB DDR4 512GB SSD RX 6700XT 12GB Rampage SHIVA CM 750W
- Windows, Office licencek kedvező áron, egyenesen a Microsoft-tól - Automata kézbesítés utalással is!
- Update 07.07. Bomba árak 2025-ben is! Üzleti - Consumer laptopok DELL FUJITSU HP LENOVO
- BESZÁMÍTÁS! ASUS VivoBook X1504ZA notebook - i3 1215U 16GB DDR4 RAM 512GB SSD Intel UHD IGP WIN11
Állásajánlatok
Cég: Promenade Publishing House Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest