Skip to content
Snippets Groups Projects
Commit 7d576dc9 authored by david's avatar david
Browse files

changements du hangman

parent 1319b616
No related branches found
No related tags found
1 merge request!1David
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
......@@ -44,7 +44,7 @@ public class Hangman
/*
Affiche l'etat de la potence en fonction du nombre d'essai.
*/
public static String showHangman(int essai)
public static void print(int essai)
{
String pot ="";
pot=pot.concat("----------\n");
......@@ -132,8 +132,7 @@ public class Hangman
}
break;
}
pot=pot.concat("");
return pot;
System.out.print(pot);
}
}
......@@ -205,7 +205,10 @@ final public class Vector {
return sum(vs).norm();
}
/*
Overrides ecrits avant le cours sur le sujet ces fonctions sont
a reecrire avec les nouvelles connaisances d'ici le deuxieme tag.
*/
@Override
public String toString() {
List<String> strings = new ArrayList<String>();
......
......@@ -32,10 +32,7 @@ final public class BinaryHeap
{
int val=this.peek();
this.set(0,0);
for(int i=0;i<this.depth();i++)
{
this.sort();
}
this.sort();
if(this.size()>0)
{
this.lstBinaryHeap.remove(this.size()-1);
......@@ -100,29 +97,35 @@ final public class BinaryHeap
private void sort()
{
int index=this.size()-1;
while(index!=0)
for(int i=0;i<this.depth();i++)
{
if(this.getParentNodeValue(index)<this.get(index))
index=this.size()-1;
while(index!=0)
{
//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())
//regarde si la valeur du parent est plus petit que l'enfant
if(this.getParentNodeValue(index)<this.get(index))
{
//les place doivent etre changer
this.switchPlace(this.getParentNodeIndex(index),index);
}
else//test la valeur d'a cote
{
//si elle existe
index=this.getSameLevelIndex(index);//passe a l'index d'a coter
if(this.getParentNodeValue(index)<this.get(index))
//test si la branche existe
if(this.getSameLevelIndex(index)<this.size())
{
//les place doivent etre changer
this.switchPlace(this.getParentNodeIndex(index),index);
//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);
}
index=this.getParentNodeIndex(index);
}
}
......@@ -169,6 +172,7 @@ final public class BinaryHeap
}
}
private int getRightNodeIndex(int index)
{
return (2*index)+1;
......
......@@ -24,10 +24,5 @@ class HangmanTests
hiddenWord=Hangman.check(hiddenWord,"david",'d');
assertEquals(hiddenWord,"d___d");
}
@Test
void check_potence()
{
String potence =Hangman.showHangman(2);
assertEquals(potence,"----------\n|/ |\n|\n|\n|\n|\n|\n|\n");
}
}
......@@ -29,6 +29,7 @@ class BinaryHeapTest
bHeap.push(1);lst.add(1);
bHeap.push(2);lst.add(2);
bHeap.push(7);lst.add(7);
bHeap.print();
bHeap.push(40);lst.add(40);
bHeap2.addAll(lst);
bHeap.print();
......@@ -43,8 +44,11 @@ class BinaryHeapTest
assertEquals(bHeap.depth(),4);
assertEquals(bHeap.peek(),100);
assertEquals(bHeap.pop(),100);
bHeap.print();
assertEquals(bHeap.pop(),40);
bHeap.print();
assertEquals(bHeap.pop(),36);
bHeap.print();
assertEquals(bHeap.size(),7);
//bHeap.print();
//assertEquals(bHeap,bHeap2);//ecrire un override pour equals
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment