IAintaBlonde.com » Sorting Algorithms

IAintaBlonde.com

Now that u know, lets get serious…………..

SORTING ALGORITHM: BUBBLE SORT

April9

Bubble Sort

This is probably the simplest way sort an array of objects. Not to ignore the fact that it is also the slowest way!

The goal is to compare two neighboring objects.

Step1:Swap them if they are in the wrong order.

Given an array a of numbers, with length n, here’s a snippet of C code for bubble sort:

for (i=0; i< a[j]) {  /* compare the two neighbors */
tmp = a[j];         /* swap a[j] and a[j+1]      */
a[j] = a[j+1];
a[j+1] = tmp;
}
}

Overall Top Posts

Top Posts for Today

  • Recent Comments:

    • matork: Sadly, we only have Windows 2000 Pro at my house, hopefully it will...
    • chethan: thnq soooooooooo muchhhhhh
    • reena: Ohh! just saw the link and downloaded pdf. Thanks a lot!
    • admin: This driver was archived well before Windows 7 was released … I...
    • carrie: does this download work for windows 7?
    • Lilu: Thank you so much for the solution to the exercises.. !!! I REALLY...
    • admin: Ha Ha. Glad to have saved your life., I mean your time :P
  • Recent Trackbacks:

    • nihotaqicetuwacn: nihotaqicetuwacn...
    • blog: hello...
    • Recipes for all: Recipe for a great treat > Tandoori Chicken !!
    • Mahdi: Comment on Network Simulation Tools: The ultimate list
    • agrotime: Handling new Hardware on Windows / Reinstalling lost drivers