funny recursion issue

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Milan Krejci

    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!=ve c->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,Nemo c", 3rd time i add "15,31,Svat ek".

    vycet_doby function goes like this:
    std::map<SD,std ::string>::iter ator itd;
    int a,b; SD s;
    vec_prace=new vecSD;
    vec_weekendu=ne w vecSD;
    vec_svatku=new vecSD;
    vec_nemoci=new vecSD;
    vec_dovolene=ne w 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?
  • Neelesh Bodas

    #2
    Re: funny recursion issue

    On Aug 20, 12:31 pm, Milan Krejci <r...@no-spam.mail.czwro te:
    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!=ve c->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,Nemo c", 3rd time i add "15,31,Svat ek".
    >
    vycet_doby function goes like this:
    std::map<SD,std ::string>::iter ator itd;
    int a,b; SD s;
    vec_prace=new vecSD;
    vec_weekendu=ne w vecSD;
    vec_svatku=new vecSD;
    vec_nemoci=new vecSD;
    vec_dovolene=ne w 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

    Comment

    • Obnoxious User

      #3
      Re: funny recursion issue

      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!=ve c->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,Nemo c", 3rd time i add "15,31,Svat ek".
      >
      vycet_doby function goes like this:
      std::map<SD,std ::string>::iter ator itd;
      int a,b; SD s;
      vec_prace=new vecSD;
      vec_weekendu=ne w vecSD;
      vec_svatku=new vecSD;
      vec_nemoci=new vecSD;
      vec_dovolene=ne w 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

      Comment

      • Milan Krejci

        #4
        Re: funny recursion issue

        well, ok, but how do you explain that

        std::vector <SD>::iterato r is;
        for (is=vec_svatku->begin();is!=ve c_svatku->end();is++) {
        from=(*is).vrat _from(); to=(*is).vrat_t o();
        if (from==15 && to==31) doba_svatek=tru e;
        }
        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.czwro te:
        >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!=ve c->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,Svat ek".
        >>
        >vycet_doby function goes like this:
        > std::map<SD,std ::string>::iter ator itd;
        > int a,b; SD s;
        > vec_prace=new vecSD;
        > vec_weekendu=ne w vecSD;
        > vec_svatku=new vecSD;
        > vec_nemoci=new vecSD;
        > vec_dovolene=ne w 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
        >

        Comment

        • Neelesh Bodas

          #5
          Re: funny recursion issue

          On Aug 20, 2:09 pm, Milan Krejci <r...@no-spam.mail.czwro te:
          well, ok, but how do you explain that
          >
          std::vector <SD>::iterato r is;
          for (is=vec_svatku->begin();is!=ve c_svatku->end();is++) {
          from=(*is).vrat _from(); to=(*is).vrat_t o();
          if (from==15 && to==31) doba_svatek=tru e;
          }
          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

          Comment

          • Peter

            #6
            Re: funny recursion issue


            "Milan Krejci" <rdw@no-spam.mail.czwro te in message
            news:fabg0h$2cd b$1@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!=ve c->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,Nemo c", 3rd time i add "15,31,Svat ek".
            >
            vycet_doby function goes like this:
            std::map<SD,std ::string>::iter ator itd;
            int a,b; SD s;
            vec_prace=new vecSD;
            vec_weekendu=ne w vecSD;
            vec_svatku=new vecSD;
            vec_nemoci=new vecSD;
            vec_dovolene=ne w 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?

            Comment

            Working...