0

To make it more readable i thought this time i will just post the link to my helpers.file. The bubblesort worked and the linary search before too.

Maybe i did something wrong in the implementation of binary search, but i get no errors.

Maybe any pro has a helping word for me .

Thanks in advance !

http://pastebin.com/hRyqncmp

1 Answer 1

0

In your search function, you are mixing up values[] and min/max.

in the beginning min should be 0 and max should be n-1 (not the values of these elements)

then in the while loop you need value z isn't needed, but you need to set

int mid = (min+max)/2

then compare value to values[mid] for your three cases.

Otherwise you will never leave your while loop, because you keep the values of the array to mid and then incrementing and decrementing this, but you aren't moving through the array.

Just as a side note, your code

int* pointerto1= &values[i];
int* pointerto2= &values[i+1];

isn't really needed.

you can just use

swap(&values[i], &values[i+1]);
2
  • Thank you very much! Just to your last point i wanna ask you. Why should i ever declare a pointer when i could just declare the variable and then access the pointer with & variable? Commented Feb 6, 2015 at 8:17
  • At times you only need a pointer - for example in a linked list to point to the next member. Then you declare a pointer. This is the section of week 5, but perhaps it helps you to watch it now: [link]youtube.com/watch?v=tQSvxT7uYQ4#t=1900 (it set the time to 31 minutes, that's where the topic starts).
    – gitterb
    Commented Feb 6, 2015 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .