From ea0b0087d06f30b59514218e4f263438fd191e65 Mon Sep 17 00:00:00 2001 From: Jazib Khan <31177908+JazibOfficial@users.noreply.github.com> Date: Thu, 4 Oct 2018 23:44:35 +0530 Subject: [PATCH] better swapping algo in bubble sort --- Sortings/bubblesort.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Sortings/bubblesort.c b/Sortings/bubblesort.c index 35e187f..a43fd51 100644 --- a/Sortings/bubblesort.c +++ b/Sortings/bubblesort.c @@ -1,7 +1,7 @@ #include int main() { - int data[100],i,n,step,temp; + int data[100],i,n,step; printf("Enter the number of elements to be sorted: "); scanf("%d",&n); for(i=0;idata[i+1]) /* To sort in descending order, change > to < in this line. */ { - temp=data[i]; - data[i]=data[i+1]; - data[i+1]=temp; + data[i+1]=data[i]+data[i+1]-(data[i]=data[i+1]); } } printf("In ascending order: ");