Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #define max 6
  3. int a[max];
  4.  
  5. int getindex(int n){
  6.   int i;
  7.   if(n > 0){
  8.     i = n%(max+1);
  9.    }
  10.   return i;
  11. }
  12.  
  13. void insert(int n){
  14.   int x = getindex(n), z;
  15.   z = x;
  16.   while((a[z] != 0) && (a[z] != -1)){
  17.     z = z++;
  18.     if(z > max){
  19.       break;
  20.     }
  21.   }
  22.   if(z > max){
  23.     printf("penuh\n");
  24.   }
  25.   else{
  26.     a[z] = n;
  27.   }
  28. }
  29.  
  30. int find(int n){
  31.   int x = getindex(n);
  32.  
  33.  while(x < max + 1){
  34.    if(a[x]==n){
  35.      return x;
  36.    }
  37.    else if(a[x] == 0){
  38.      return -1;
  39.    }
  40.     x++;
  41.   }
  42.   return -1;
  43.  }
  44.  
  45. int main()
  46. {
  47.   insert(22180412);
  48.   insert(22180987);
  49.   insert(22181066);
  50.   insert(22768930);
  51.   insert(22374649);
  52.  printf("%d",find(223748675));
  53.   return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement