Hello, I have to make a sorting table sorting by merging, but I have a problem here that I return the sort when I go 1 or a value> 9 as a value in my table.
-desktop: ~ / iut / algo / sorting $ g + +-o-merger fusion.cc lcgicc
-desktop: ~ / iut / algo / sorting $. / fusion
9
5
8
7
8
23
4
3
3
4
5
7
8
-1208258560
8
9
Here is my program:
# include <iostream>
using namespace std;
void merge (int array [], int deb1, FIN1 int, int fin2)
(
int table1 [FIN1-deb1 1];
FIN1 int deb2 = 1;
int compt1 = deb1;
int compt2 = deb2;
int i;
/ / we copy the elements from start of table
for (i = deb1; i <= FIN1; i + +)
(
table1 [i-deb1] = array [i];
)
for (i = deb1; i <= fin2; i + +)
(
if (compt2 == (fin2 +1)) / / is that all elements of the second table were used
(
array [i] = table1 [compt1-deb1] / / add the remaining elements of the first table
compt1 + +;
)
else if (table1 [compt1-deb1] <array [compt2])
(
array [i] = table1 [compt1-deb1] / / add an element of the first table
compt1 + +;
)
else if (compt1! = deb2)
(
array [i] = array [compt2] / / add an element of the second table
compt2 + +;
)
)
)
tri_fusion_bis void (int array [], int deb, int fin)
(
if (deb! = end)
(
int middle = (end + deb) / 2;
tri_fusion_bis (painting, deb, middle);
tri_fusion_bis (array, mid +1, end);
Merge (table, deb, middle, end);
)
)
triFusion void (int array [], int length)
(
if (length> 0)
(
tri_fusion_bis (array, 0, length-1);
)
)
int main ()
(
int t [50];
t [0] = 9;
t [1] = 5;
t [2] = 8;
t [3] = 7;
t [4] = 8;
t [5] = 23;
t [6] = 4;
t [7] = 3;
for (int i = 0; i <= 7; i + +)
court <<t [i] <<endl;
court <<endl <<endl <<endl;
triFusion (t, 8);
for (int i = 0; i <= 7; i + +)
court <<t [i] <<endl;
)
Thank you in advance for your help.



Reply With Quote
Copyright Techfuels
Bookmarks