Hirdetés
- 3D nyomtatás
- OLED TV topic
- Amlogic S905, S912 processzoros készülékek
- AMD Catalyst™ driverek topikja
- Videós, mozgóképes topik
- AMD vs. INTEL vs. NVIDIA
- NVIDIA GeForce RTX 5080 / 5090 (GB203 / 202)
- A Logitech egere összement a mosásban, és ez lett belőle
- NVIDIA GeForce RTX 4080 /4080S / 4090 (AD103 / 102)
- TCL LCD és LED TV-k
Ú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?:))
- MSI Katana 2 év garival, bomba áron!
- Apple iPhone 16 Pro Max 256GB 99% Akku! Újszerű,Dobozos,Tartozékaival! 1 Év Garanciával!
- Samsung Galaxy A56 5G 8/256GB Újszerű,Kártyafüggetlen,Dobozos,Tartozékaival! 1 Év Garanciával!
- Logitech g920+ váltó
- Kingston HyperX KHX8500D2BK2/4G DDR2-1066 MHz CL5 2 x 2 GB Kit
- Gamer PC-Számítógép! Csere-Beszámítás! R5 5500 / 16GB DDR4 / RX 6600 8GB / 512 GB SSD
- GYÖNYÖRŰ iPhone 12 64GB White -1 ÉV GARANCIA - Kártyafüggetlen, MS4013
- PS Plus előfizetések kedvező áron
- HIBÁTLAN iPhone 15 Pro Max 256GB Natural Titanium-1 ÉV GARANCIA - Kártyafüggetlen, MS4231
- HIBÁTLAN iPhone 15 Pro Max 256GB Natural Titanium -1 ÉV GARANCIA -Kártyafüggetlen, 100% Akkumulátor
Állásajánlatok
Cég: Laptopszaki Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest


