Skip to content
Snippets Groups Projects
Commit 185af25c authored by fefe's avatar fefe
Browse files
parents af9d6d78 249d2168
No related branches found
No related tags found
No related merge requests found
java.lang.Math
java.util.Random
public class BinaryHeap{
private int[] heap;
//private int[] heap;
public BinaryHeap(){
this.heap = new int[10];
}
public BinaryHeap(int size){
//this.heap = new int[10];
heap = int[size];
}
public BinaryHeap(int[] values){
/*public BinaryHeap(int[] values){
int[] newHeap = new int[values.length];
for (int value : values){
for (int i = 0; i < newHeap.length; i++){
......@@ -14,10 +18,61 @@ public class BinaryHeap{
System.out.println(newHeap[1]);
}
this.heap = newHeap;
}*/
public static populate(int nbValues){
System.out.println("gfgdg");
for (int i = 0; i < nbValues; i++) {
randomVal = Math.random();
//System.out.println(randomVal);
this.heap[i] = randomVal;
}
//return heap;
}
private static void Echange(ref int a, ref int b){
int swap = a;
a = b;
b = swap;
}
private static void Tamiser(int[] arbre, int noeud, int n){
int k = noeud;
int j = 2 * k;
while (j <= n)
{
if ((j < n) && (arbre[j] < arbre[j + 1]))
j++;
if (arbre[k] < arbre[j])
{
Tri.Echange(ref arbre[k], ref arbre[j]);
k = j;
j = 2 * k;
}
else
break;
}
}
public static void TriParTas(BinaryHeap arbre){
for (int i = arbre.Length >> 1; i >= 0; i--)
Tri.Tamiser(arbre, i, arbre.Length - 1);
for (int i = arbre.Length - 1; i >= 1; i--)
{
Tri.Echange(ref arbre[i], ref arbre[0]);
Tri.Tamiser(arbre, 0, i - 1);
}
}
public static void main(String[] args){
BinaryHeap test = new BinaryHeap(new int[]{10,2});
BinaryHeap test = new BinaryHeap();
test.populate(5);
//System.out.println(Arrays.toString(test));
System.out.println("aaa");
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment