Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void selectionSort(int* num, int size)
  5. {
  6. int min, temp;
  7. for (int i = 0; i < size - 1; i++)
  8. {
  9. min = i;
  10.  
  11. for (int j = i + 1; j < size; j++)
  12. {
  13. if (num[j] > num[min])
  14. min = j;
  15. }
  16. temp = num[i];
  17. num[i] = num[min];
  18. num[min] = temp;
  19. }
  20. }
  21.  
  22. int main()
  23. {
  24. int num;
  25. cout << "Enter integer value: ";
  26. cin >> num;
  27.  
  28. int* arr = new int[num];
  29. for (int i = 0; i < num; i++)
  30. {
  31. cin >> arr[i];
  32. }
  33. cout << "=====================================================" << endl;
  34. for (int i = 0; i < num; i++)
  35. {
  36. if (arr[i] > 0) { selectionSort(arr, num); }
  37. }
  38. for (int i= 0; i < num; i++)
  39. {
  40. cout << arr[i] << " ";
  41. }
  42. cout << endl << endl;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement