-
It seems with the sequential sort. Here is the ouput when I execute my program:
Code:
Enter an integer to search the array or -1 to quit:12
Sequential search found the value: 12 in element -1 with 1000 items scanned.
Binary search found the value: 12 in element 14 with 6 items scanned.
Enter an integer to search the array or -1 to quit:2
Sequential search found the value: 2 in element 877 with 878 items scanned.
Binary search found the value: 2 in element 2 with 8 items scanned.
Enter an integer to search the array or -1 to quit:14
Sequential search found the value: 14 in element -1 with 1000 items scanned.
Binary search found the value: 14 in element 19 with 10 items scanned.
Enter an integer to search the array or -1 to quit:32
Sequential search found the value: 32 in element -1 with 1000 items scanned.
Binary search found the value: 32 in element 34 with 10 items scanned.
-
Sheesh talk about missing a big one...
Code:
int arraycpy(int *a, int *b) {
int x;
x=0;
while((a[x]=b[x])!='\0') {
x++;
}
}
Ok the problem may not be apparent but since this looks for a null terminator to a numberic array...you are lucky you aren't getting seg faults more than anything. That said you should copy the arrays like this:
Example:
Code:
int arraycpy(int *dst, int *src, size_t size) {
do {
dst++=*src++;
} while(--size);
}
I changed the names of the parameters to make things more clear. Why do this? Well it may have something to do with the fact that you were putting the random numbers int ia, but then having ib copy its values over into ia.
-
I am getting a "line 15 invalid lvalue in assignment" for:
-
That statement is really scary. You should try breaking it up into smaller pieces.
-
I changed arraycpy to this and it seems to work now:
Code:
int arraycpy(int *a, int *b) {
int x;
x=0;
while(x!=1000) {
b[x]=a[x];
x++;
}
}
-
oops that should be:
This is what happens when you miss with your carret when copying and pasting :)
-
-
Yeah no problem and sorry about the typo. I don't really see lines such as that as too much obfustication, but maybe its because its just fairly common to see. You could break up the operation into smaller parts as sean_mackrory suggested.
Example:
Code:
int arraycpy(int *dst, int *src, size_t size) {
do {
*dst = *str;
dst++;
src++;
} while(--size);
}
But as you can see thats not a exactly a far cry from how I originally had it.