#include <stdio.h> #include <stdint.h> void bubble_sort_desc(uint8_t *arr, uint8_t n) { // Your logic here for (int i = n - 1; i > 0; i--){ for (int j = n -1; j > 0; j--){ uint8_t *a = arr +n - j; uint8_t *b = arr + n -j - 1; if ( *a > *b){ uint8_t temp = *b; *b = *a; *a = temp; } } } } int main() { uint8_t n; scanf("%hhu", &n); uint8_t arr[100]; for (uint8_t i = 0; i < n; i++) { scanf("%hhu", &arr[i]); } bubble_sort_desc(arr, n); for (uint8_t i = 0; i < n; i++) { printf("%hhu", arr[i]); if(i < n-1){ printf(" "); } } return 0; }
Test Cases
Test Results
Input
5 10 3 5 2 7
Expected Output
10 7 5 3 2