Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Bubble Sort

  • 17-02-2005 03:30PM
    #1
    Registered Users, Registered Users 2 Posts: 3,165 ✭✭✭


    Does anyone know the Bubble sort code for C that works? I'ved tried a few codes from various sites and it doesn't work.


Comments

  • Moderators, Society & Culture Moderators Posts: 9,688 Mod ✭✭✭✭stevenmu


    This may seem like a drastic solution, but have you tried doing it yourself ?
    I'm presuming it's a coursework problem you've been given ? If so, the bubble is a fairly basic thing to do, if you can't figure out how to at least get close to being able to do it, you're going to be screwed later on.


  • Closed Accounts Posts: 25 maxcherry


    OK peeps look at exercise 2 here http://www.ee.surrey.ac.uk/Teaching/Courses/C/clab5.html

    This should get you started


  • Closed Accounts Posts: 7,230 ✭✭✭scojones


    I'd like to see the bubble sort code that doesn't work.


  • Registered Users, Registered Users 2 Posts: 629 ✭✭✭str8_away


    What string or number secquence you are trying that make bubble sort fail?


  • Closed Accounts Posts: 154 ✭✭smorton


    void sort(int array[],int length_of_array,char ascend_or_descend)
    {
    int i,j,ascend=1;
    double buffer;
    if(ascend_or_descend!='a')
    {
    ascend=-1;
    }
    for(i=0;i<length_of_array;i++)
    {
    for(j=0;j<length_of_array-1;j++)
    {
    if((array[j]*ascend)>(array[j+1]*ascend))
    {
    buffer=array[j];
    array[j]=array[j+1];
    array[j+1]=buffer;
    }
    }
    }
    }

    //if you pass 'a' to the function for ascending_or_descending, it'll sort in
    //ascending order, otherwise it'll sort in descending


  • Advertisement
  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 95,997 Mod ✭✭✭✭Capt'n Midnight


    Out of curiousity is there any serious real world application for bubble sort anymore ?


  • Moderators, Society & Culture Moderators Posts: 9,688 Mod ✭✭✭✭stevenmu


    I think it's mainly just used for teaching algorithms and FOR loops etc.


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Out of curiousity is there any serious real world application for bubble sort anymore ?
    No, it's a useless algorithm and was never state of the art.
    Some people use it for teaching purposes, but many people argue that using such a poor algorithm for teaching is counter-productive.


Advertisement