Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void swapp(int arr[], int i, int min)
- {
- int t = arr[min];
- arr[min] = arr[i];
- arr[i] = t;
- }
- void fasterSelectionSort(int arr[],const int MAX)
- {
- for (int i = 0; i < MAX - 1; i++)
- {
- int min = i;
- for (int j = i + 1; j < MAX; j++)
- {
- if (arr[j] < arr[min])
- {
- min = j;
- }
- if (j == MAX - 1)
- {
- swapp(arr, i, min);
- }
- }
- }
- }
- void fillarr(int arr[], const int MAX)
- {
- for (int i = 0; i < MAX; i++)
- {
- arr[i] = MAX - i;
- }
- }
- void printarr(int arr[],const int MAX)
- {
- for (int i = 0; i < MAX; i++)
- {
- cout << arr[i] << " ";
- }
- }
- int main()
- {
- const int MAX = 50000;
- int arr[MAX];
- fillarr(arr, MAX);
- cout << "The unsorted arr is \n";
- printarr(arr, MAX);
- fasterSelectionSort(arr, MAX);
- cout << " \n\nThe sorted arr is \n";
- printarr(arr, MAX);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement