diff --git a/sorting/selection_sort.c b/sorting/selection_sort.c index c7547608c7..17ecae9fdb 100644 --- a/sorting/selection_sort.c +++ b/sorting/selection_sort.c @@ -9,7 +9,8 @@ #include /** - * Swapped two numbers using pointer + * Swap two integers using pointer + * * @param first first pointer of first number * @param second second pointer of second number */ @@ -21,9 +22,12 @@ void swap(int *first, int *second) } /** - * Selection sort algorithm implements + * Implements the Selection Sort algorithm. + * * @param arr array to be sorted - * @param size size of array + * @param n NUmber of elements in the array + * Time Complexity:0(n^2) + * Space Complexity: O(1) */ void selectionSort(int *arr, int size) { @@ -39,7 +43,7 @@ void selectionSort(int *arr, int size) } if (min_index != i) { - swap(arr + i, arr + min_index); + swap(&arr[i], &arr[min_index]); } } }