TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: THOMAS MAEDER
from: BRIAN WOOD
date: 1998-01-18 16:42:00
subject: sort algorithm

 TM> If you think that bubble sort is a good sorting algorithm, I  have  to
 TM> object.
If you have a better one, then why not share it?  For the price of a few
lines, I thought it was a very interesting example.  Below is the way I
learned bubblesort.  Good excercise for understanding pointers and the
address-of operator.  The other used a different loop strategy, which is
why I thought it was a good example.
// bubbleSort( int *array, int size)
void bubbleSort(int *a, const int s)
{
   void swap(int *, int *);
   for(int p=1; p a[j+1])
            swap(&a[j], &a[j+1]);
}
void swap(int *a, int *b)
{
   int t=*a;
   *a=*b;
   *b=t;
}
L8r,
bw
... I couldn't possibly fail to disagree with you less.
--- Blue Wave/DOS v2.20
---------------
* Origin: River Canyon Rd. BBS Chattanooga, Tn (1:362/627)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.