Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include "helpers.h"
- #include <stdbool.h>
- bool search( int value, int values[], int n)
- {
- int lo =0;
- int hi=n-1;
- int mid=(lo+hi)/2;
- int found=0;
- while (lo <=hi)
- {
- if (values[mid] == value)
- {
- found=1;
- return true;
- }
- else if (values[mid] < value)
- (lo = mid+1);
- else
- {
- (hi = mid-1);
- mid = ((lo+hi)/2);
- }
- }
- if (found==0)
- return false;
- else
- return true;
- }
- void sort(int values[], int n)
- {
- for (int i = 0, swap ; i < ( n - 1 ); i++)
- {
- for (int j = 0 ; j < n - i - 1; j++)
- {
- if (values[j] > values[j+1])
- {
- swap = values[j];
- values[j] = values[j+1];
- values[j+1] = swap;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement