943,865 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2826
  • C++ RSS
You are currently viewing page 4 of this multi-page discussion thread; Jump to the first page
May 12th, 2008
0

Re: Bubble Sort

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:
C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  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. }
C++ Syntax (Toggle Plain Text)
  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?
Reputation Points: 361
Solved Threads: 97
Posting Pro
Radical Edward is offline Offline
526 posts
since May 2008
May 12th, 2008
0

Re: Bubble Sort

I think thats clear enough, thanx a lot guys
Reputation Points: 26
Solved Threads: 19
Posting Whiz in Training
Traicey is offline Offline
283 posts
since Mar 2008
May 12th, 2008
0

Re: Bubble Sort

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?
Reputation Points: 10
Solved Threads: 1
Light Poster
DigitalPackrat is offline Offline
33 posts
since Jan 2008
May 13th, 2008
0

Re: Bubble Sort

Thanx a lot dude!!!!!!
Reputation Points: 26
Solved Threads: 19
Posting Whiz in Training
Traicey is offline Offline
283 posts
since Mar 2008
May 13th, 2008
0

Re: Bubble Sort

Yup.
Reputation Points: 10
Solved Threads: 1
Light Poster
DigitalPackrat is offline Offline
33 posts
since Jan 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Read File>>>>
Next Thread in C++ Forum Timeline: Data base connection with c++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC