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
No related branches found
No related tags found
2 merge requests!2Tanguy,!1David
This commit is part of merge request !2. Comments created here will be created in the context of that merge request.
...@@ -23,6 +23,30 @@ final public class BinaryHeap ...@@ -23,6 +23,30 @@ final public class BinaryHeap
this.sort(); 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) public static void populate(BinaryHeap heap, int size)
{ {
Random rand = new Random(); Random rand = new Random();
......
...@@ -15,6 +15,7 @@ class BinaryHeapTest ...@@ -15,6 +15,7 @@ class BinaryHeapTest
{ {
BinaryHeap bHeap= new BinaryHeap(); BinaryHeap bHeap= new BinaryHeap();
BinaryHeap bHeapRand= new BinaryHeap(); BinaryHeap bHeapRand= new BinaryHeap();
BinaryHeap bHeapEmpty= new BinaryHeap();
BinaryHeap.populate(bHeapRand,20); BinaryHeap.populate(bHeapRand,20);
bHeap.push(100); bHeap.push(100);
bHeap.push(19); bHeap.push(19);
...@@ -30,5 +31,9 @@ class BinaryHeapTest ...@@ -30,5 +31,9 @@ class BinaryHeapTest
//bHeapRand.print(); //bHeapRand.print();
assertEquals(bHeap.size(),10); assertEquals(bHeap.size(),10);
assertEquals(bHeapRand.size(),20); 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