Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Bubble Sort

Options
  • 17-02-2005 3:30pm
    #1
    Registered Users 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,689 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 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: 91,687 Mod ✭✭✭✭Capt'n Midnight


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


  • Moderators, Society & Culture Moderators Posts: 9,689 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