Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > funny recursion issue

Reply
Thread Tools

funny recursion issue

 
 
Milan Krejci
Guest
Posts: n/a
 
      08-20-2007
hi, this is something i really don't see where the problem might be.

std::vector <LCDRange *>::iterator it;
LCDRange *l;
for (it=vec->begin();it!=vec->end();it++) { //is executed N times
l=*(it);
....
l->p_doba->vycet_doby(t);
}

first i add "15,31,Dovolena" to l->p_doba->SDoby. next loop i add
"15,31,Nemoc", 3rd time i add "15,31,Svatek".

vycet_doby function goes like this:
std::map<SD,std::string>::iterator itd;
int a,b; SD s;
vec_prace=new vecSD;
vec_weekendu=new vecSD;
vec_svatku=new vecSD;
vec_nemoci=new vecSD;
vec_dovolene=new vecSD;
for (itd = SDoby.begin(); itd != SDoby.end(); itd++)
{ s=itd->first;
a=s.vrat_from();
b=s.vrat_to();
std::cout << a << "-" << b << ":" << itd->second << std::endl;
....}
this, however, outputs:
15-31ovolena
15-31:Nemoc
15-31:Svatek
15-31ovolena
15-31:Nemoc
15-31:Svatek
15-31ovolena
15-31:Nemoc
15-31:Svatek

N times (3 times in this case). i thought it should output only once for
each l->p_doba->SDoby. do you get my point?
 
Reply With Quote
 
 
 
 
Neelesh Bodas
Guest
Posts: n/a
 
      08-20-2007
On Aug 20, 12:31 pm, Milan Krejci <r...@no-spam.mail.cz> wrote:
> hi, this is something i really don't see where the problem might be.
>
> std::vector <LCDRange *>::iterator it;
> LCDRange *l;
> for (it=vec->begin();it!=vec->end();it++) { //is executed N times
> l=*(it);
> ...
> l->p_doba->vycet_doby(t);
>
> }
>
> first i add "15,31,Dovolena" to l->p_doba->SDoby. next loop i add
> "15,31,Nemoc", 3rd time i add "15,31,Svatek".
>
> vycet_doby function goes like this:
> std::map<SD,std::string>::iterator itd;
> int a,b; SD s;
> vec_prace=new vecSD;
> vec_weekendu=new vecSD;
> vec_svatku=new vecSD;
> vec_nemoci=new vecSD;
> vec_dovolene=new vecSD;
> for (itd = SDoby.begin(); itd != SDoby.end(); itd++)
> { s=itd->first;
> a=s.vrat_from();
> b=s.vrat_to();
> std::cout << a << "-" << b << ":" << itd->second << std::endl;
> ...}
> this, however, outputs:
> 15-31ovolena
> 15-31:Nemoc
> 15-31:Svatek
> 15-31ovolena
> 15-31:Nemoc
> 15-31:Svatek
> 15-31ovolena
> 15-31:Nemoc
> 15-31:Svatek
>
> N times (3 times in this case). i thought it should output only once for
> each l->p_doba->SDoby. do you get my point?


Can't get much out of this code, but my guess is that it is because
you are using a for loop inside vycet_doby function which is itself in
a for loop.
-N

 
Reply With Quote
 
 
 
 
Obnoxious User
Guest
Posts: n/a
 
      08-20-2007
On Mon, 20 Aug 2007 09:31:29 +0200, Milan Krejci wrote:

> hi, this is something i really don't see where the problem might be.
>
> std::vector <LCDRange *>::iterator it;
> LCDRange *l;
> for (it=vec->begin();it!=vec->end();it++) { //is executed N times
> l=*(it);
> ...
> l->p_doba->vycet_doby(t);
> }
>
> first i add "15,31,Dovolena" to l->p_doba->SDoby. next loop i add
> "15,31,Nemoc", 3rd time i add "15,31,Svatek".
>
> vycet_doby function goes like this:
> std::map<SD,std::string>::iterator itd;
> int a,b; SD s;
> vec_prace=new vecSD;
> vec_weekendu=new vecSD;
> vec_svatku=new vecSD;
> vec_nemoci=new vecSD;
> vec_dovolene=new vecSD;
> for (itd = SDoby.begin(); itd != SDoby.end(); itd++)
> { s=itd->first;
> a=s.vrat_from();
> b=s.vrat_to();
> std::cout << a << "-" << b << ":" << itd->second << std::endl;
> ...}
> this, however, outputs:
> 15-31ovolena
> 15-31:Nemoc
> 15-31:Svatek
> 15-31ovolena
> 15-31:Nemoc
> 15-31:Svatek
> 15-31ovolena
> 15-31:Nemoc
> 15-31:Svatek
>
> N times (3 times in this case). i thought it should output only once for
> each l->p_doba->SDoby. do you get my point?


Post a compilable reduced version of your code demonstrating the problem.

--
Obnoxious User
 
Reply With Quote
 
Milan Krejci
Guest
Posts: n/a
 
      08-20-2007
well, ok, but how do you explain that

std::vector <SD>::iterator is;
for (is=vec_svatku->begin();is!=vec_svatku->end();is++) {
from=(*is).vrat_from(); to=(*is).vrat_to();
if (from==15 && to==31) doba_svatek=true;
}
if (doba_svatek) { ts<<"svatek X\n"; t->append("svatek"); }
ts=writes into a file
t=writes a text to a text window.

in the window i can see "svatek" but in the file there is svatek X three
or whatever times.

Neelesh Bodas napsal(a):
> On Aug 20, 12:31 pm, Milan Krejci <r...@no-spam.mail.cz> wrote:
>> hi, this is something i really don't see where the problem might be.
>>
>> std::vector <LCDRange *>::iterator it;
>> LCDRange *l;
>> for (it=vec->begin();it!=vec->end();it++) { //is executed N times
>> l=*(it);
>> ...
>> l->p_doba->vycet_doby(t);
>>
>> }
>>
>> first i add "15,31,Dovolena" to l->p_doba->SDoby. next loop i add
>> "15,31,Nemoc", 3rd time i add "15,31,Svatek".
>>
>> vycet_doby function goes like this:
>> std::map<SD,std::string>::iterator itd;
>> int a,b; SD s;
>> vec_prace=new vecSD;
>> vec_weekendu=new vecSD;
>> vec_svatku=new vecSD;
>> vec_nemoci=new vecSD;
>> vec_dovolene=new vecSD;
>> for (itd = SDoby.begin(); itd != SDoby.end(); itd++)
>> { s=itd->first;
>> a=s.vrat_from();
>> b=s.vrat_to();
>> std::cout << a << "-" << b << ":" << itd->second << std::endl;
>> ...}
>> this, however, outputs:
>> 15-31ovolena
>> 15-31:Nemoc
>> 15-31:Svatek
>> 15-31ovolena
>> 15-31:Nemoc
>> 15-31:Svatek
>> 15-31ovolena
>> 15-31:Nemoc
>> 15-31:Svatek
>>
>> N times (3 times in this case). i thought it should output only once for
>> each l->p_doba->SDoby. do you get my point?

>
> Can't get much out of this code, but my guess is that it is because
> you are using a for loop inside vycet_doby function which is itself in
> a for loop.
> -N
>

 
Reply With Quote
 
Neelesh Bodas
Guest
Posts: n/a
 
      08-20-2007
On Aug 20, 2:09 pm, Milan Krejci <r...@no-spam.mail.cz> wrote:
> well, ok, but how do you explain that
>
> std::vector <SD>::iterator is;
> for (is=vec_svatku->begin();is!=vec_svatku->end();is++) {
> from=(*is).vrat_from(); to=(*is).vrat_to();
> if (from==15 && to==31) doba_svatek=true;
> }
> if (doba_svatek) { ts<<"svatek X\n"; t->append("svatek"); }
> ts=writes into a file
> t=writes a text to a text window.
>
> in the window i can see "svatek" but in the file there is svatek X three
> or whatever times.
>
> Neelesh Bodas napsal(a):


Please donot top-post.
Please provide small-sized compilable code that demonstrates the
problem.

-N

 
Reply With Quote
 
Peter
Guest
Posts: n/a
 
      08-21-2007

"Milan Krejci" <> wrote in message
news:fabg0h$2cdb$...
> hi, this is something i really don't see where the problem might be.
>
> std::vector <LCDRange *>::iterator it;
> LCDRange *l;
> for (it=vec->begin();it!=vec->end();it++) { //is executed N times
> l=*(it);
> ...
> l->p_doba->vycet_doby(t);
> }
>
> first i add "15,31,Dovolena" to l->p_doba->SDoby. next loop i add
> "15,31,Nemoc", 3rd time i add "15,31,Svatek".
>
> vycet_doby function goes like this:
> std::map<SD,std::string>::iterator itd;
> int a,b; SD s;
> vec_prace=new vecSD;
> vec_weekendu=new vecSD;
> vec_svatku=new vecSD;
> vec_nemoci=new vecSD;
> vec_dovolene=new vecSD;
> for (itd = SDoby.begin(); itd != SDoby.end(); itd++)
> { s=itd->first;
> a=s.vrat_from();
> b=s.vrat_to();
> std::cout << a << "-" << b << ":" << itd->second << std::endl;
> ...}
> this, however, outputs:
> 15-31ovolena
> 15-31:Nemoc
> 15-31:Svatek
> 15-31ovolena
> 15-31:Nemoc
> 15-31:Svatek
> 15-31ovolena
> 15-31:Nemoc
> 15-31:Svatek
>
> N times (3 times in this case). i thought it should output only once for
> each l->p_doba->SDoby. do you get my point?



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
va_arg... recursion: changing arguments and the using recursion jononanon@googlemail.com C Programming 8 04-26-2012 08:37 PM
Funny Pictures ! Funny Jokes ! Drink Recipes, Reviews & More ! joevan Computer Support 0 06-29-2006 06:00 PM
OT: The Interview - Real, Funny...Real Funny The Rev [MCT] MCSE 42 05-31-2005 10:42 PM
recursion with perl B McInnes Perl 4 11-04-2003 06:08 AM
Output buffering problems during recursion Tim Mohler Perl 1 09-16-2003 12:35 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57