What is this sorting algorithm called?

for(int i=0; i<n-1; i++) { for(int j=i+1; j<n; j++) { if(a[i] > a[j]) { /* Swap a[i] and a[j] */ } } } 

PS Given the name of the algorithm, you can easily find the appropriate source code. But it's hard for me to do the opposite: D

Change Oh! If it is a sorting of bubbles, then what is it called:

 for(int i=0; i<n; i++) { for(int j=0; j<n-1; j++) { if(a[j] > a[j+1]) { /* Swap a[j] and a[j+1] */ } } } 

I thought this second β€œbubble” reduces the number of elements, so I thought it was really a bubble. If the first type of bubbles, what is the name of the second?

+6
sorting algorithm
source share
4 answers

First, Sort Selection is selected, and the second that you added is Bubble sort!

+6
source share

The name of this algorithm is bubble sorting .

Edit: sorry for the mistake (confuse me with j in a[i] > a[j] ). The first is sorting

+4
source share

The first is sorting sorting, the second is Sorting bubbles

+4
source share

There are so many sorting algorithms. Here are just a few:

  • Sort sort
  • Bubble Sort
  • Heap Sort
  • Combine Sort
  • Sort Count
  • Sorting
  • Quick sort
-one
source share

All Articles