Answer to Question #273117 in UNIX/Linux Programming for Kumaraguru

Question #273117

Sort {5, 1,12,-5, 16,2,12,14} using selection short

1
Expert's answer
2021-11-29T10:31:47-0500
#incclude <algorithm>
int main() {
  int arr[] = {5, 1,12,-5, 16,2,12,14};
  int size = sizeof(arr) / sizeof(arr[0]);
  for (int i = 0; i < size; i++) {
    int iMin = i;
    for (int j = i + 1; j < size; j++) {
      if (arr[iMin] > arr[j]) {
        iMin = j;
      }
    }
    std::swap(arr[i], arr[iMin]);
  }
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS