Thread: what is the purpose of this function..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    what is the purpose of this function..

    true=1
    false=0

    i dont need to a solution
    i want a way by which i can decide
    what this function do

    here i have arrays of input
    very complicated
    where to start
    how to go?

    Code:
    int what2(char* s1,char* s2,char*s3,int* n1,int* n2)
    {
           int sz1=strlen(s1),sz2=strlen(s2);
        
          if (!*s3)
          {
                *n1=*n2=0;
                return true;
          }
         if (what1 (s1,s3) && what2(s1,s2,s3+sz1,n1,n2))
         {
             (*n1)++;
             return true;
         }
         if (what1 (s2,s3)&& what2(s1,s2,s3+sz2,n1,n2))
        {
             (*n2)++;
            return true;
        }
         return false;
    }
    Last edited by transgalactic2; 03-23-2009 at 01:04 PM.

  2. #2
    Registered User
    Join Date
    Aug 2008
    Posts
    129
    It changes the values at n1 and n2 depending on the values of the three strings.

    If s3 holds 0, both n1 and n2 are also set to 0 and we're done. Otherwise, we check the return values of what1 and what2.

    If what1(s1, s3) is true, we recursively call what2 with a slightly different s3 - with the first sz1 characters removed. If what2 also returns true, we increment n1 and finish.

    If what1(s2, s3) is true, we recursively call what2 with a slightly different s3 - with the first sz2 characters removed. If what2 also returns true, we increment n2 and finish.

    If none of those conditions was true, we're done.

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    what input ro use in order to find a pattern

  4. #4
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Do we know what the what1() function does?

    The whole thing looks kinda pointless. Both strings s1 and s2 never change, so why keep passing them through? And why recalculate their lengths every time? And why keep passing addresses n1 and n2 down the recursion? Lots of redundancy.

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    it seems to me like counting number of times s1 is present in s3 and s2 is present there (if the what1 returns true when first argument is equvalent to the beginning of the second string argument

    s1 ="123"
    s2="ab"
    s3="123123123abab"
    in a result n1 should be 3, n2 - 2
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM