How to sort only odd elements of array by Shell sort

212 Views Asked by At

I have a task to sort array by shell sort, goara sort and quick sort. But in the task also says that I need sort only odd elements. I know how to do it by bubble sort but how in shell, goara, and quick I don't know.

I found a Shell sort method in Net by I don't know how to sort only odd elements.

void shell_Sort_num(int mas[], int size_mas) {

    int incr = size_mas/2;
     while( incr > 0 ) {
         for ( int i=incr+1; i<size_mas; i++ ) {
             int j = i-incr;
             while ( j > 0 )
                 if ( mas[j] > mas[j+incr] ){
                     swap(mas[j], mas[j+incr]);
                     j = j - incr;
                 }
                 else j = 0;
         }
         incr = incr/2
     }
    cout << "Symbols array after Shell sort: \n"; print_array_num(mas,size_mas); }
0

There are 0 best solutions below