Timeline for Helpers code never finds a needle
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Aug 25, 2015 at 23:23 | comment | added | uma1966 | @REW. I am also getting similar errors. If I use linear search,everything is fine. If I use binary search very similar to your code, check50 passes all the tests ,find works manually to find the needle. But if you pipe the results using ./generate 1000 50 |./find 127,it does not work. I will be interested to know whether you have traced thecause of this error. uma1966 | |
Jul 17, 2015 at 1:34 | comment | added | REW | I have used printf, and I can see that numbers are sorting. If I just enter several numbers by hand, it sorts them, and it works correctly. However, if I use generate to input the numbers, it sorts the number, but it never finds the number, even if it is there. Would it help if I posted my code again? | |
Jul 16, 2015 at 23:12 | comment | added | lyflonglerner | REW, Have you verified that your sort is working properly? Since binary requires a presorted array, an error in the sort routine might produce bizarre results? | |
Jul 16, 2015 at 19:55 | comment | added | Cliff B | Without knowing what you've changed, I have no way to answer that. But if you had made only the changes noted, it should work. | |
Jul 16, 2015 at 18:55 | comment | added | REW | Ah! Thanks so much! Something so simple to overlook. I have changed "n" to "value". I changed a few more things, and I thought I was getting somewhere. Now if I generate 10 numbers, any value I try to find always returns true. But if I generate 1000 numbers, any value I find is always false. I am not sure what would cause this. Any advice on what to look for? | |
Jul 16, 2015 at 4:51 | history | edited | Cliff B | CC BY-SA 3.0 |
added 169 characters in body
|
Jul 16, 2015 at 4:34 | history | answered | Cliff B | CC BY-SA 3.0 |