473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

funny recursion issue

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-31:Dovolena
15-31:Nemoc
15-31:Svatek
15-31:Dovolena
15-31:Nemoc
15-31:Svatek
15-31:Dovolena
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?
Aug 20 '07 #1
5 1444
On Aug 20, 12:31 pm, Milan Krejci <r...@no-spam.mail.czwrote:
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-31:Dovolena
15-31:Nemoc
15-31:Svatek
15-31:Dovolena
15-31:Nemoc
15-31:Svatek
15-31:Dovolena
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

Aug 20 '07 #2
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-31:Dovolena
15-31:Nemoc
15-31:Svatek
15-31:Dovolena
15-31:Nemoc
15-31:Svatek
15-31:Dovolena
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
Aug 20 '07 #3
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.czwrote:
>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-31:Dovolena
15-31:Nemoc
15-31:Svatek
15-31:Dovolena
15-31:Nemoc
15-31:Svatek
15-31:Dovolena
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
Aug 20 '07 #4
On Aug 20, 2:09 pm, Milan Krejci <r...@no-spam.mail.czwrote:
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

Aug 20 '07 #5

"Milan Krejci" <rd*@no-spam.mail.czwrote in message
news:fa***********@news.vol.cz...
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-31:Dovolena
15-31:Nemoc
15-31:Svatek
15-31:Dovolena
15-31:Nemoc
15-31:Svatek
15-31:Dovolena
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?

Aug 21 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Peri | last post by:
I'm trying to create Python parser/interpreter using ANTLR. Reading grammar from language refference I found: or_expr::= xor_expr | or_expr "|" xor_expr For me it looks like infinite recursion....
43
by: Lorenzo Villari | last post by:
I've tried to transform this into a not recursive version but without luck... #include <stdio.h> void countdown(int p) { int x;
9
by: Nak | last post by:
Hi there, I was wondering what the normal procedure for making a license provider require licensing was? I have just created a licensing class library and I want to make it require a license...
75
by: Sathyaish | last post by:
Can every problem that has an iterative solution also be expressed in terms of a recursive solution? I tried one example, and am in the process of trying out more examples, increasing their...
18
by: MTD | last post by:
Hello all, I've been messing about for fun creating a trial division factorizing function and I'm naturally interested in optimising it as much as possible. I've been told that iteration in...
12
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an...
5
by: case.learning | last post by:
Hi everyone, I'm a C++ novice. I'm trying to learn recursion and have written this piece of code but it doesn't work. Could you help me to see where it goes wrong? Thanks. bool...
2
by: Brian Takita | last post by:
Hello, we are implementing a function that uses recursion to poll a server. This implementation seems like it would cause a memory ramp up and possibly a stack overflow. Am I correct? Is there...
4
by: gvi | last post by:
Hi, I am not sure if recursion is the solution. But here is my issue. This has to be done on Oracle 9i and only in the procedure and no front end involved. I have a teacher and he has a class...
35
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.