From 22481b1fccae029ec7b5cce7f4a5aeb1d16c54aa Mon Sep 17 00:00:00 2001 From: Manish kumar chaurasia <30630740+kmanish31@users.noreply.github.com> Date: Sun, 28 Oct 2018 08:53:50 +0530 Subject: [PATCH] updated code of selection sort in this article (#20058) --- .../algorithms/sorting-algorithms/selection-sort/index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/guide/english/algorithms/sorting-algorithms/selection-sort/index.md b/guide/english/algorithms/sorting-algorithms/selection-sort/index.md index f4ca57ced3..be23b4c273 100644 --- a/guide/english/algorithms/sorting-algorithms/selection-sort/index.md +++ b/guide/english/algorithms/sorting-algorithms/selection-sort/index.md @@ -21,16 +21,16 @@ But, how would you write the code for finding the index of the second smallest v ### Implementation in C/C++ ```C -for(int i = 0; i < n; i++) +for(int i = 0; i < n-1; i++) { int min_index = i; - int min_element = a[i]; + for(int j = i +1; j < n; j++) { - if(a[j] < min_element) + if(a[j] < a[min_index]) { - min_element = a[j]; + min_index = j; } }