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
Merge requests
!2
Tanguy
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Tanguy
david.carballo/poo2019numeric:Tanguy
into
master
Overview
0
Commits
28
Pipelines
0
Changes
2
Open
tanguy.dietrich
requested to merge
david.carballo/poo2019numeric:Tanguy
into
master
5 years ago
Overview
0
Commits
28
Pipelines
0
Changes
2
Expand
merge request de tanguy vers master
0
0
Merge request reports
Viewing commit
4f543c18
Prev
Next
Show latest version
2 files
+
83
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
4f543c18
Ecriture de .push() pour le BinaryHeap
· 4f543c18
tanguy.dietrich
authored
5 years ago
src/main/java/ch/hepia/structure/BinaryHeap.java
+
68
−
2
Options
@@ -8,14 +8,80 @@ import java.util.function.Function;
final
public
class
BinaryHeap
{
final
private
List
<
Integer
>
lstBinaryHeap
;
private
BinaryHeap
()
private
int
taille
;
public
BinaryHeap
()
{
lstBinaryHeap
=
new
ArrayList
<
Integer
>();
this
.
lstBinaryHeap
=
new
ArrayList
<
Integer
>();
this
.
taille
=
0
;
}
public
void
push
(
int
value
)
{
this
.
taille
++;
this
.
lstBinaryHeap
.
add
(
value
);
this
.
sort
();
}
private
void
sort
()
{
int
index
=
this
.
size
()-
1
;
while
(
index
!=
0
)
{
if
(
this
.
getParentNodeValue
(
index
)<
this
.
get
(
index
))
{
//les place doivent etre changer
this
.
switchPlace
(
this
.
getParentNodeIndex
(
index
),
index
);
//test la valeur d'a cote
}
else
{
//test si la branche existe
if
(
this
.
getSameLevelIndex
(
index
)<
this
.
size
())
{
//si elle existe
index
=
this
.
getSameLevelIndex
(
index
);
//passe a l'index d'a coter
if
(
this
.
getParentNodeValue
(
index
)<
this
.
get
(
index
))
{
//les place doivent etre changer
this
.
switchPlace
(
this
.
getParentNodeIndex
(
index
),
index
);
}
}
}
index
=
this
.
getParentNodeIndex
(
index
);
}
}
private
void
switchPlace
(
int
index1
,
int
index2
)
{
int
tmp
;
tmp
=
this
.
lstBinaryHeap
.
get
(
index1
);
this
.
set
(
index1
,
this
.
get
(
index2
));
this
.
set
(
index2
,
tmp
);
}
public
void
print
()
{
for
(
int
val:
lstBinaryHeap
)
{
System
.
out
.
println
(
val
);
}
}
public
int
size
()
{
return
this
.
taille
;
}
private
int
getSameLevelIndex
(
int
index
)
{
if
(
index
%
2
==
0
)
{
return
index
-
1
;
}
else
{
return
index
+
1
;
}
}
private
int
getRightNodeIndex
(
int
index
)
Loading