CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2010
    Posts
    5

    Question Please I want a solution to this question؟

    public int Evaluate(s,t){
    for loop {
    if(s==0 || t==0)
    return 0;
    }
    else if{
    y=Evaluate(s,t-1);
    return s+y;
    }
    }



    By using stack to find
    z=Evaluate(2,2)=???????????????????
    Dont use Recourion
    please help me ?!!

  2. #2
    Join Date
    Jun 2010
    Posts
    5

    Re: Please I want a solution to this question؟

    Note :
    When I answered the question
    The answer is 6
    But some of my answer was 4
    I am confused about now

  3. #3
    Join Date
    Jun 2010
    Posts
    5

    Talking Re: Please I want a solution to this question؟

    the answer is 4
    http://store2.up-00.com/Jun10/bPo33786.jpg
    this quistion comming for me in the finale exam for Data Structuers

  4. #4
    Join Date
    May 2009
    Posts
    2,413

    Re: Please I want a solution to this question؟

    I'm not quite sure what you're asking.

    Is Evaluate given in some real language or is it pseudocode? What does,

    for loop {

    mean?

  5. #5
    Join Date
    Jun 2010
    Posts
    5

    Cool Re: Please I want a solution to this question؟

    oh yes
    i dont main for loop
    I do not remember the text of a good question

    ****************************************
    public int Evaluate(s,t){
    for {
    if(s==0 || t==0)
    return 0;
    }
    else if{
    y=Evaluate(s,t-1);
    return s+y;
    }
    }

    ****************************************

    By using stack to find
    z=Evaluate(2,2)=???????????????????
    Dont use Recourion



    The solution described in the link http://www.4shared.com/photo/0Nu72OYi/9999999999.html

    Is the correct solution, as told by Dr.



    Thus, the question was almost



    Thank you for your interest

  6. #6
    Join Date
    Jul 2010
    Posts
    4

    Re: Please I want a solution to this question؟

    How do you solve it using recurion ?

  7. #7
    Join Date
    Jul 2010
    Posts
    4

    Re: Please I want a solution to this question؟

    Hello, strange, so strange, I am still think it is 0 not 4

    1.public int Evaluate(s,t){
    2.{
    3.if(s==0 || t==0)
    4.return 0;
    5.}
    6.else if{
    7.y=Evaluate(s,t-1); // this
    8.return s+y;
    9.}
    10.}

    Line 7 rerun line 1, so no value is put for y
    t=2-1=1
    s=2
    line 3 checks t and s
    unsatisfactorily, line 6 come again, line 7 again rerun line 1, still no value for y
    t=1-1=0
    s=2
    Now t=0
    line 2-3 checks t=0 so satisfied it returns 0

    So the final result is 0, line 8 never reaches

    Answer=0

    Am I right ?
    Hello, I am a college junior

  8. #8
    Join Date
    May 2009
    Posts
    2,413

    Re: Please I want a solution to this question؟

    Quote Originally Posted by Lazyboy View Post
    Am I right ?
    Does it stay put now, the 1 to 10 lines? Is this the version of the Evaluate function you're asking about?

    And what are you asking again please? Be precise.

    And who is salemqeshta in relation to lazyboy?

    Sorry for letting out some steam here but why is it so god dammed hard to state a problem in a precise and understandable way?
    Last edited by nuzzle; July 5th, 2010 at 08:45 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured