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.
varn=a.Length;varswaps=0;for(vari=0;i<n;i++){for(varj=0;j<n-1;j++){if(a[j]>a[j+1]){vartmp=a[j];a[j]=a[j+1];a[j+1]=tmp;swaps++;}}}Console.WriteLine("Array is sorted in {0} swaps.",swaps);Console.WriteLine("First Element: {0}",a[0]);Console.WriteLine("Last Element: {0}",a[n-1]);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sorting: Bubble Sort
You are viewing a single comment's thread. Return to all comments →
C#