We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
staticvoidcountSwaps(int[]a){intmax=a.Max();intmin=a.Min();inttemp=0;intswaps=0;for(intx=0;x<a.Length;x++){for(inty=0;y<a.Length-1;y++){if(a[y]>a[y+1]){temp=a[y];a[y]=a[y+1];a[y+1]=temp;swaps++;}}}Console.WriteLine("Array is sorted in {0} swaps.",swaps);Console.WriteLine("First Element: {0}",min);Console.WriteLine("Last Element: {0}",max);}
Sorting: Bubble Sort
You are viewing a single comment's thread. Return to all comments →
C#:
Passed all test cases: