Re: Bubble search ( descending)

"robertnorwood2000" <[email protected]>
Newsgroups gmane.comp.programming.cppug
Message-ID <[email protected]>
Check out: 
http://ptgtraining.com/CyberClassroom/0025o8/ch05/05_06/index.htm

You wil have to register. It is a pretty decsent book. Includes the 
code I believe you are looking for.

--- In [email protected], Marcel <marcelsol@y...> wrote:
> /* If adjacent items are out of order ==> swap them */
> the code is well commented, I would give a try on this
> line
> 
> --- John Payette <petote_22960@y...> wrote:
> > I am having trouble finding the code changes I need
> > to make to create
> > a sort list in descending order.  Anyone out there
> > with some advice?
> > 
> > #include <iostream>
> > using namespace std;
> > 
> > /* 
> > 	Bubble Sort Technique 
> > 	 
> > */
> > 
> > 
> > #define swap(a,b)   { int t; t=a; a=b; b=t;}
> > 
> > int bubble(int array[], int end, int start)
> > /*Input & Output:
> > 	array[]: array to be sorted, and sorted output
> > after sorting from
> > start to end inclusive
> > 	start: start index of items to be sorted
> > 	end: end index of items to be sorted
> > 	bubble: int Boolean flag for success/failure for
> > function
> > */
> > {
> >     int i, j;
> > 	int flag = 1;
> >     /* Make (end - start + 1) passes through the
> > array bubbling the
> > lightest (smallest) item to the top */
> >     
> > 	for(i=start;i<end;i++)  // i < end not <= end since
> > the last item
> > will be sorted with itself
> >     {
> >         /* From the first element to the end of the
> > unsorted section */
> >         for(j=end;j>i;j--)
> >         {
> >            /* If adjacent items are out of order ==>
> > swap them */
> >            if(array[j-1]>array[j])
> > 		   swap(array[j-1],array[j]); // bubble the
> > lighter item up
> >         }
> >     }
> > 	
> > 	return flag;
> > }    
> > 
> > 
> > int main()
> > {
> > 	const int maxIndex=16;
> > 	int myFlag=1;
> > 	int i=0;
> > 	int sortThis[] = {9, 1, 2, 3, 4, 5, 3, 2, 2, 2, 1,
> > 7, 70, 60, 50 , 40
> > , 30};
> > 
> > 	if(myFlag=bubble(sortThis, 0, maxIndex))
> > 		for(i=0; i<= maxIndex ; i++)
> > 			cout << sortThis[i] << "  ";
> > 
> > 	return myFlag;
> > }
> > 
> > 
> > 
> > ------------------------ Yahoo! Groups Sponsor
> > 
> > To unsubscribe from this group, send an email to:
> > [email protected]
> > 
> >  
> > 
> > Your use of Yahoo! Groups is subject to
> > http://docs.yahoo.com/info/terms/ 
> > 
> > 
> 
> 
> __________________________________
> Do you Yahoo!?
> Exclusive Video Premiere - Britney Spears
> http://launch.yahoo.com/promos/britneyspears/



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs from home.
Over 14,500 titles. Free Shipping
& No Late Fees. Try Netflix for FREE!
http://us.click.yahoo.com/I3w.vC/hP.FAA/3jkFAA/EbFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.