Skip to content
Snippets Groups Projects
Commit 186c9f84 authored by tanguy.dietrich's avatar tanguy.dietrich
Browse files

Ecriture de .depth() pour le BinaryHeap

parent e1173670
Branches
Tags
2 merge requests!2Tanguy,!1David
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
...@@ -35,6 +35,18 @@ final public class BinaryHeap ...@@ -35,6 +35,18 @@ final public class BinaryHeap
} }
} }
public int depth()
{
int index=this.size();
int dptCompteur=1;
while(index!=0)
{
index=this.getParentNodeIndex(index);
dptCompteur++;
}
return dptCompteur;
}
public boolean exist(int k) public boolean exist(int k)
{ {
for(int val:this.lstBinaryHeap) for(int val:this.lstBinaryHeap)
......
...@@ -35,5 +35,6 @@ class BinaryHeapTest ...@@ -35,5 +35,6 @@ class BinaryHeapTest
assertEquals(bHeapRand.isEmpty(),false); assertEquals(bHeapRand.isEmpty(),false);
assertEquals(bHeap.exist(7),true); assertEquals(bHeap.exist(7),true);
assertEquals(bHeap.exist(42),false); assertEquals(bHeap.exist(42),false);
assertEquals(bHeap.depth(),4);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment