Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
poo2019numeric
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
steven.liatti
poo2019numeric
Commits
e1173670
Commit
e1173670
authored
5 years ago
by
tanguy.dietrich
Browse files
Options
Downloads
Patches
Plain Diff
Ecriture de .isEmpty(), et .exist() pour le BinaryHeap
parent
bdf5a810
No related branches found
No related tags found
2 merge requests
!2
Tanguy
,
!1
David
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/ch/hepia/structure/BinaryHeap.java
+24
-0
24 additions, 0 deletions
src/main/java/ch/hepia/structure/BinaryHeap.java
src/test/java/ch/hepia/structure/AppTest.java
+5
-0
5 additions, 0 deletions
src/test/java/ch/hepia/structure/AppTest.java
with
29 additions
and
0 deletions
src/main/java/ch/hepia/structure/BinaryHeap.java
+
24
−
0
View file @
e1173670
...
@@ -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
();
...
...
This diff is collapsed.
Click to expand it.
src/test/java/ch/hepia/structure/AppTest.java
+
5
−
0
View file @
e1173670
...
@@ -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
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment