Skip to content

Instantly share code, notes, and snippets.

@vlaleli
Created December 18, 2024 21:23
Show Gist options
  • Select an option

  • Save vlaleli/0099474b3d8c0e20da563fdf9aaef47c to your computer and use it in GitHub Desktop.

Select an option

Save vlaleli/0099474b3d8c0e20da563fdf9aaef47c to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
const int SIZE = 10;
int arr[SIZE];
cout << "Enter " << SIZE << " array elements:" << endl;
for (int i = 0; i < SIZE; i++) {
cin >> arr[i];
}
for (int i = 0; i < SIZE / 2 - 1; i++) {
int minIndex = i;
for (int j = i + 1; j < SIZE / 2; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
int temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
}
cout << "Array after sorting the first half:" << endl;
for (int i = 0; i < SIZE; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment