0

Write c++ program that sort the numbers -11,20,0,6,72,11 in ascending /descending using recursive function pleasr help.

27th Mar 2022, 10:35 AM
Misganaw Guadie
Misganaw Guadie - avatar
7 Respuestas
+ 2
Misgun Evan Working. Just make another function for descending order. Code will be same just condition is changed as I mentioned in previous reply
27th Mar 2022, 10:54 AM
A͢J
A͢J - avatar
+ 1
Attempts?
27th Mar 2022, 10:37 AM
A͢J
A͢J - avatar
+ 1
Misgun Evan For descending you can check in opposite: if (arr[i] < arr[i + 1])
27th Mar 2022, 10:47 AM
A͢J
A͢J - avatar
0
#include <iostream> using namespace std; void recurbublSort(int arr[], int len){    int temp;    if (len == 1){       return;    }    for (int i=0; i<len-1; i++){       if (arr[i] > arr[i+1]){          temp=arr[i];          arr[i]=arr[i+1];          arr[i+1]=temp;       }    }    len=len-1;    recurbublSort(arr, len); } int main(){    int Arr[] = {-11,20,0,6,72,11};    int length = sizeof(Arr)/sizeof(Arr[0]);    recurbublSort(Arr, length);    cout<<"Sorted array : ";    for(int i=0;i<length;i++){       cout<<Arr[i]<<" ";    }    return 0; }
27th Mar 2022, 10:38 AM
Misganaw Guadie
Misganaw Guadie - avatar
0
It only works ascending
27th Mar 2022, 10:39 AM
Misganaw Guadie
Misganaw Guadie - avatar
- 1
It doesn't work please write a full programm tnx
27th Mar 2022, 10:51 AM
Misganaw Guadie
Misganaw Guadie - avatar
- 1
Ok tnx ❤ please am waiting for your response
27th Mar 2022, 10:55 AM
Misganaw Guadie
Misganaw Guadie - avatar