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:

    • admin: Ha Ha. Glad to have saved your life., I mean your time :P
    • Naomi: TY so much! you saved my life. Well, not my life, but you saved me...
    • David M: bohzo (hello) Very, very nice site!
    • ivenxoyz: Hi I saw your blog. You have done a good job, I really liked your...
    • Monique: Are you geared up for the new season? Can’t wait!
    • Ethan: It’s easy to get caught up in the little things, isn’t it?...
    • OweEng2: I love Super Mario especially Yoshi since the Gameboy days, but I...
  • 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