Bubble Sort

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 351
Reputation: Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about Radical Edward has a spectacular aura about 
Solved Threads: 62
Radical Edward's Avatar
Radical Edward Radical Edward is offline Offline
Posting Whiz

Re: Bubble Sort

 
0
  #31
May 12th, 2008
In niek_e's example, the init-expression, cond-expression, and loop-expression are all optional as long as you include the separating semicolons. That's why an infinite "forEVER" loop looks like this:
  1. for (;;) {
  2. ...
  3. }
As long as the loop does what you want, the syntax is very flexible. In Ed's experience, the usual culprits are a very long initialization that makes the loop line too long and a more complicated update:
  1. // So long it makes more sense outside the loop
  2. std::vector<std::pair<std::string, double> >::size_type index = 0;
  3.  
  4. for (; index != v.size(); ++index) {
  5. ...
  6. }
  7.  
  8. // As a part of the loop (too long)
  9. for (std::vector<std::pair<std::string, double> >::size_type index = 0; index != v.size(); ++index) {
  10. ...
  11. }
  1. // n isn't incremented with every loop
  2. for (n = 0; n < 10 && std::getline(std::cin, input); ) {
  3. if (input[0] == '*')
  4. ++n;
  5. }
Cool, huh?
If at first you don't succeed, keep on sucking until you do succeed.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 268
Reputation: Traicey is an unknown quantity at this point 
Solved Threads: 19
Traicey's Avatar
Traicey Traicey is offline Offline
Posting Whiz in Training

Re: Bubble Sort

 
0
  #32
May 12th, 2008
I think thats clear enough, thanx a lot guys
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 33
Reputation: DigitalPackrat is an unknown quantity at this point 
Solved Threads: 1
DigitalPackrat's Avatar
DigitalPackrat DigitalPackrat is offline Offline
Light Poster

Re: Bubble Sort

 
0
  #33
May 12th, 2008
Reiterating the point, niek_e made, its possible. All of them are not necessary, in fact none are.
Also, I did not want to use sort variable outside the loop, so I used it inside as, if there are more bubble sorts and I use the sort variable again and don't initialize it, well, that would give me some headache. Won't it?
[Catchy Signature Here]
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 268
Reputation: Traicey is an unknown quantity at this point 
Solved Threads: 19
Traicey's Avatar
Traicey Traicey is offline Offline
Posting Whiz in Training

Re: Bubble Sort

 
0
  #34
May 13th, 2008
Thanx a lot dude!!!!!!
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 33
Reputation: DigitalPackrat is an unknown quantity at this point 
Solved Threads: 1
DigitalPackrat's Avatar
DigitalPackrat DigitalPackrat is offline Offline
Light Poster

Re: Bubble Sort

 
0
  #35
May 13th, 2008
Yup.
[Catchy Signature Here]
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC