Skip to content

Commit 164cefc

Browse files
authored
Merge pull request #4 from CodingFactory-Repos/Feature/Tri-insertion
Feature/tri insertion
2 parents 09da783 + d3ee0d2 commit 164cefc

4 files changed

Lines changed: 71 additions & 0 deletions

File tree

Tri-insertion/Main.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

Tri-insertion/Tri-insertion.iml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

Tri-insertion/algorithm.algo

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Correspond à la fonction Trouve disponible
2+
FONCTION Tri-insertion (Tableau T)
3+
4+
DEBUT
5+
taille = taille tableau
6+
Pour i = 1, i < taille , i + 1
7+
j = i- 1
8+
x = tableau[i]
9+
Pour i de 1 à taille(T) - 1
10+
TANTQUE j => 0 et tableau[j-1] > x
11+
tableau[j] <- tableau[j-1]
12+
j <- j-1
13+
tableau[j] <- x
14+
Retourne le tableau
15+
FIN
16+
FINFONCTION
17+

Tri-insertion/src/Main.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.util.Arrays;
2+
public class Main {
3+
public static void main(String[] args) {
4+
System.out.print("\033[H\033[2J");
5+
6+
int[] tableau = { 1, 3, 7, 2, 6, 4, 5, 8, 10, 9 };
7+
8+
System.out.println("Tableau de test : "+Arrays.toString(tri(tableau)));
9+
10+
}
11+
12+
public static int[] tri(int[] tableau)
13+
{
14+
int taille = tableau.length;
15+
16+
for (int i = 1; i < taille; i++)
17+
{
18+
int x = tableau[i];
19+
int j = i-1;
20+
21+
while(j >= 0 && tableau[j] > x)
22+
{
23+
tableau[j+1] = tableau[j];
24+
j--;
25+
}
26+
tableau [j+1] = x;
27+
}
28+
return tableau;
29+
}
30+
31+
32+
}

0 commit comments

Comments
 (0)