void sortOddIndexes(int arr[], int size) { for(int i = 1; i < size; i += 2) { for(int j = i + 2; j < size; j += 2) { if(arr[i] > arr[j]) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } }
int main() { int size; cout << "Enter the size of the array: "; cin >> size;
int arr[size]; cout << "Enter the elements of the array: "; for(int i = 0; i < size; i++) { cin >> arr[i]; } sortOddIndexes(arr, size); cout << "Sorted array with odd indexes: "; for(int i = 1; i < size; i += 2) { cout << arr[i] << " "; } return 0;
using namespace std;
void sortOddIndexes(int arr[], int size) {
for(int i = 1; i < size; i += 2) {
for(int j = i + 2; j < size; j += 2) {
if(arr[i] > arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
int main() {
int arr[size];int size;
cout << "Enter the size of the array: ";
cin >> size;
cout << "Enter the elements of the array: ";
for(int i = 0; i < size; i++) {
cin >> arr[i];
}
sortOddIndexes(arr, size);
cout << "Sorted array with odd indexes: ";
for(int i = 1; i < size; i += 2) {
cout << arr[i] << " ";
}
return 0;
}