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
Printable View
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
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.
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:
you can search the web for more information.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;
}
>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
hey, '.............' i hope you arent planning on keeping that name. ;)
Why, no, in fact, I'm not. This any better? :)Quote:
Originally posted by ...
hey, '.............' i hope you arent planning on keeping that name. ;)
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;
}
}
}
much... :PQuote:
Originally posted by 28:06:42:12
Why, no, in fact, I'm not. This any better? :)