My issue
Give me the complete code of it
My code
#include <stdio.h>
#include <stdbool.h>
// Complete the cmp function to solve the problem
bool cmp(int* a, int* b) {
if(*a>*b){
return true;
}else{
return false;
}
}
void sort(int arr[][2], int n) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < n - 1; j++) {
if(cmp(arr[j], arr[j + 1])) {
// Swap logic
for(int k = 0; k < 2; k++) {
int temp = arr[j][k];
arr[j][k] = arr[j + 1][k];
arr[j + 1][k] = temp;
}
}
}
}
}
int main() {
int n;
scanf("%d", &n);
int arr[n][2];
for(int i = 0; i < n; i++) {
scanf("%d %d", &arr[i][0], &arr[i][1]);
}
sort(arr, n);
for(int i = 0; i < n; i++) {
printf("%d %d\n", arr[i][0], arr[i][1]);
}
return 0;
}
Learning course: Analysis and Design of Algorithms
Problem Link: Comparator Function in Analysis and Design of Algorithms