Thread: bubble sort?

  1. #1
    Registered User brianptodd's Avatar
    Join Date
    Oct 2002
    Posts
    66

    bubble sort?

    Has anyone heard of sorting an array using a bubble sort. I have never heard of it, and I can't find any information on it.

    Brian

  2. #2
    .............
    Guest
    Bubble sort is a sorting algorithm in which you sort by comparing adjacent elements in an array. If the elements are out of order, you swap them. It works ok on small arrays, I guess, but in general...it's crap. Hope that was what you were looking for.

  3. #3
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    I think it's the simplest sorting algorithm I now, and i think the slowest...
    it's like this.
    if you have an array[size]
    you can so this:
    Code:
    const int size;
    int array[size];
    int temp;
    
    for( int pass=0; pass< size-1; pass++ )
         for ( int ij=0; i<size-1; ij++ )
              if ( array[i] > array[i+1] ) //check
              {
                   temp = array[i];          //swap variables
                   array[i] = array[i+1]
                   array[i+1] = temp;
              }
    you can search the web for more information.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Has anyone heard of sorting an array using a bubble sort.
    I may have seen something concerning a thing called "bubble sort" quite some time ago. It was referred to in terms of something else called "bogo sort".

    >I have never heard of it, and I can't find any information on it.
    I suggest you get a book (just about any book) on programming and look in the index. If the algorithm isn't there then try another book. I figure that it will take you at most two tries to find it.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    hey, '.............' i hope you arent planning on keeping that name.
    I came up with a cool phrase to put down here, but i forgot it...

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    9
    Originally posted by ...
    hey, '.............' i hope you arent planning on keeping that name.
    Why, no, in fact, I'm not. This any better?

  7. #7
    Registered User
    Join Date
    Jun 2002
    Posts
    79
    Try this.
    Code:
    int array[limit],ctr,temp;
    bool flag=0;
    while(flag==0)
    {
       flag=1;
       for(ctr=0; ctr<limit-1; ++ctr)
       {
          if(array[ctr]>array[ctr+1])
          {
             temp=array[ctr]; array[ctr]=array[ctr+1]; array[ctr+1]=temp;
             flag=0;
          }
       }
    }

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    Originally posted by 28:06:42:12
    Why, no, in fact, I'm not. This any better?
    much... :P
    I came up with a cool phrase to put down here, but i forgot it...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My bubble sort only sorts once
    By Muller in forum C Programming
    Replies: 8
    Last Post: 03-27-2009, 04:36 PM
  2. help with debug (bubble sort algorithm)
    By lbraglia in forum C Programming
    Replies: 5
    Last Post: 10-19-2007, 05:24 PM
  3. Bubble Sort... which type?
    By gflores in forum C++ Programming
    Replies: 8
    Last Post: 08-15-2004, 04:48 AM
  4. Bubble Sort, Qucik Sort
    By insomniak in forum C Programming
    Replies: 2
    Last Post: 03-15-2003, 04:54 PM
  5. optimizing bubble sort
    By Sargnagel in forum C Programming
    Replies: 14
    Last Post: 01-23-2003, 06:27 AM