fix: stop swapping over bounds

This commit is contained in:
kevinnls committed 2021-09-20 10:34:26 +05:30
1 parent 621c51d037
commit 2079046d46
1 file changed
+1 -1
+1 -1
View File
@@ -35,7 +35,7 @@ int* sort(int* arr, int length){
int changes = 0;
do {
changes = 0;
for(int i=1; i<length; i++){
for(int i=0; i<length-1; i++){
if(arr[i]>arr[i+1]){
if(DEBUG)printf("need to swap [%d]->%d and [%d]->%d\n",i,arr[i],i+1,arr[i+1]);
swap(arr, i, i+1);