Hirdetés
- Samsung Galaxy S25 Ultra - titán keret, acélos teljesítmény
- Az 5 legnagyobb bénázás a mobilpiacon idén
- Bemutatkozott a Poco X7 és X7 Pro
- Telekom mobilszolgáltatások
- Ezek a OnePlus 12 és 12R európai árai
- A piac legerősebb kameráját ígéri a Xiaomi 17 Ultra
- Apple iPhone 16 - ígéretek földje
- Samsung Galaxy S23 Ultra - non plus ultra
- Redmi Note 13 4G
- Azonnali mobilos kérdések órája
Ú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?:))
- SZINTE ÚJ Razer Blackshark V2+sound card Bolti ár:50k INGYEN FOXPOST
- SZINTE ÚJ Razer Kaira X White Bolti ár:15k INGYEN FOXPOST
- Razer Nari Bolti ár:50k INGYEN FOXPOST
- ÚJ Razer Barracuda X Bolti ár:40k INGYEN FOXPOST
- Lenovo Yoga Pro 9i Hordozható Gamer Tervező laptop -25% 14,5" i7-13705H 16/1TB RTX 4050 6GB 144Hz 3K
- Keresünk iPhone 16/16 Plus/16e/16 Pro/16 Pro Max
- BESZÁMÍTÁS! Apple MacBook Pro 14 M4 Max 36GB RAM 1TB SSD macbook garanciával hibátlan működéssel
- Samsung Galaxy S24 128GB, Kártyafüggetlen, 1 Év Garanciával
- BESZÁMÍTÁS! Huawei Watch 4 Pro eSIM okosóra garanciával hibátlan működéssel
- Apple iPhone 16 Pro Max - Black Titanium - 256GB - Akku: 90% - Megkímélt állapot!
Állásajánlatok
Cég: Laptopszaki Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest


