0

Here's the code for my pset 3, which fails to find the '127' in the stack. Any hints will be massively appreciated:

bool search(int value, int values[], int n)
{
    for(int i = 0; i < n; i++)
    {
        if(values[i] == value)
            return true;
    }    
    return false;
}

I even tried replacing 'value' with '127' in the code, just to check what's wrong, and it won't work even then. Any ideas? [I know you could add things like making sure than n is greater than 0 etc. but for now I'm trying to finish the search itself.] ;)

7
  • Are you sure 127 is in the array when you pass it? Your code seems ok to me.
    – ChrisG
    Jul 30, 2015 at 13:18
  • According to the pset spec, it should be. (The spec says we should use the 127 as a test case.) Jul 30, 2015 at 13:28
  • Yes but are you inserting it?
    – ChrisG
    Jul 30, 2015 at 13:33
  • I think so. I , mean, you're given a line you're meant to copy into the terminal to check the search function, and that inserts the number for you. Jul 30, 2015 at 13:36
  • Did you re-make all after changing the search function? Also are you sure you are running ./generate 1000 50 | ./find 127 exactly?
    – ChrisG
    Jul 30, 2015 at 13:59

0

You must log in to answer this question.

Browse other questions tagged .