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

Ecriture de .isEmpty(), et .exist() pour le BinaryHeap

parent bdf5a810
Branches
No related tags found
2 merge requests!2Tanguy,!1David
......@@ -23,6 +23,30 @@ final public class BinaryHeap
this.sort();
}
public boolean isEmpty()
{
if(this.size()==0)
{
return true;
}
else
{
return false;
}
}
public boolean exist(int k)
{
for(int val:this.lstBinaryHeap)
{
if(k==val)
{
return true;
}
}
return false;
}
public static void populate(BinaryHeap heap, int size)
{
Random rand = new Random();
......
......@@ -15,6 +15,7 @@ class BinaryHeapTest
{
BinaryHeap bHeap= new BinaryHeap();
BinaryHeap bHeapRand= new BinaryHeap();
BinaryHeap bHeapEmpty= new BinaryHeap();
BinaryHeap.populate(bHeapRand,20);
bHeap.push(100);
bHeap.push(19);
......@@ -30,5 +31,9 @@ class BinaryHeapTest
//bHeapRand.print();
assertEquals(bHeap.size(),10);
assertEquals(bHeapRand.size(),20);
assertEquals(bHeapEmpty.isEmpty(),true);
assertEquals(bHeapRand.isEmpty(),false);
assertEquals(bHeap.exist(7),true);
assertEquals(bHeap.exist(42),false);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment