Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

agreed, except that the reason it's never a good idea to use bubble sort is that insertion sort is just as simple and always performs much better; there are cases where insertion sort really is the right thing to use despite its usually quadratic performance

there might even be a case where the single-loop sort is the right thing to use, despite its abominable performance, because it's simpler than bubble sort or insertion sort; i think it's 12 amd64 instructions, 40 bytes

    for (i = 1; i < n; i++)
      if (a[i-1] > a[i]) t = a[i], a[i] = a[i-1], a[i-1] = t, i = 0;
but i haven't seen it yet


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: