Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void selectionSort(int* num, int size)
- {
- int min, temp;
- for (int i = 0; i < size - 1; i++)
- {
- min = i;
- for (int j = i + 1; j < size; j++)
- {
- if (num[j] > num[min])
- min = j;
- }
- temp = num[i];
- num[i] = num[min];
- num[min] = temp;
- }
- }
- int main()
- {
- int num;
- cout << "Enter integer value: ";
- cin >> num;
- int* arr = new int[num];
- for (int i = 0; i < num; i++)
- {
- cin >> arr[i];
- }
- cout << "=====================================================" << endl;
- for (int i = 0; i < num; i++)
- {
- if (arr[i] > 0) { selectionSort(arr, num); }
- }
- for (int i= 0; i < num; i++)
- {
- cout << arr[i] << " ";
- }
- cout << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement