Nov 27, 2016 at 9:54am UTC
@Chervil could you say me where the problem is?
Last edited on Nov 27, 2016 at 11:34am UTC
Nov 27, 2016 at 10:23am UTC
If you want to print the progress, then insert print after every swap.
Last edited on Nov 27, 2016 at 10:23am UTC
Nov 27, 2016 at 10:37am UTC
i did it in the funktion sor
void sort::sor()
{
for(j=0;j<10;j++)
for(i=j+1;i<10;i++)
{if(a[j]>a[i]){
swap ();
print();}
}}
but it is giving me in the output:
3 9 5 6 1 7 2 0 8 4
3 9 5 6 1 7 2 0 8 4
Nov 27, 2016 at 10:40am UTC
1 2 3 4 5 6
void print(data (&arr)[size])
{
for (int i=0; i<size;++i)
std::cout<<arr[i]<<' ' ;
std::cout<<'\n' ;
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void operator ()(data (&arr)[size])
{
bool is_sorted=false ;
while (!is_sorted)
{
is_sorted=true ;
for (int unsigned i=0; i<size-1;++i)
{
if (arr[i]>arr[i+1])
{
swap(arr[i],arr[i+1]);
print(arr);
is_sorted=false ;
}
}
}
};
Output:
1 5 2 9 8 0
1 5 2 8 9 0
1 5 2 8 0 9
1 2 5 8 0 9
1 2 5 0 8 9
1 2 0 5 8 9
1 0 2 5 8 9
0 1 2 5 8 9
0 1 2 5 8 9
Last edited on Nov 27, 2016 at 10:41am UTC
Nov 27, 2016 at 11:09am UTC
i have to do with my code because my university wants the program with 3 funktions which i wrote it :)
Nov 27, 2016 at 11:20am UTC
but im not sure if i have to do with sort::sort