Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define max 6
- int a[max];
- int getindex(int n){
- int i;
- if(n > 0){
- i = n%(max+1);
- }
- return i;
- }
- void insert(int n){
- int x = getindex(n), z;
- z = x;
- while((a[z] != 0) && (a[z] != -1)){
- z = z++;
- if(z > max){
- break;
- }
- }
- if(z > max){
- printf("penuh\n");
- }
- else{
- a[z] = n;
- }
- }
- int find(int n){
- int x = getindex(n);
- while(x < max + 1){
- if(a[x]==n){
- return x;
- }
- else if(a[x] == 0){
- return -1;
- }
- x++;
- }
- return -1;
- }
- int main()
- {
- insert(22180412);
- insert(22180987);
- insert(22181066);
- insert(22768930);
- insert(22374649);
- printf("%d",find(223748675));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement