Advertisement
informaticage

Binary Search template excercise

May 17th, 2021
1,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <stdbool.h>
  5.  
  6. #define LEN 16
  7.  
  8. bool binary_search(int V[], size_t v_len, int to_find);
  9.  
  10. int main(void) {
  11.   int V[LEN];
  12.   srand(time(NULL));
  13.   for (int i = 0; i < LEN; i++) {
  14.     V[i] = rand() % 100 + 1;
  15.   }
  16.  
  17.   printf("[ ");
  18.   for (int i = 0; i < LEN; i++) {
  19.     printf("%d ", V[i]);
  20.   }
  21.   printf("]\n");
  22.  
  23.   for (int i = 0; i < LEN; i++) {
  24.     for (int j = i + 1; j < LEN; j++) {
  25.       if (V[i] > V[j]) {
  26.         int temp = V[i];
  27.         V[i] = V[j];
  28.         V[j] = temp;
  29.       }
  30.     }
  31.   }
  32.  
  33.   printf("[ ");
  34.   for (int i = 0; i < LEN; i++) {
  35.     printf("%d ", V[i]);
  36.   }
  37.   printf("]\n");
  38.   return 0;
  39. }
  40.  
  41. bool binary_search(int V[], size_t v_len, int to_find) {
  42.   // Restituire true se to_find esiste in V
  43.   // False altrimenti
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement