Hoşgeldin Misafir

C backets hashing

MiRaT

13 Kas 2017
2,077 Mesaj

Aktiflik

Seviye

Deneyim

TIM / GÖREV:
Kod:
#include <stdio.h>
#include <stdlib.h>

//Backets hashing
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int mod (int x){  //mod al
	return x % 10;
}
int a[10][1] = {NULL};

int put (int n, int r){
	while (a[r][0]!= NULL && a[r][1]!=NULL)
	r++;
	if (a[r][0]!=NULL)
	return a[r][1]=n;
	
	return a[r][0]=n;
	
}
int put1 (int n, int r ){
	
	return a[r][1]=n;
	
}
int get (n){
	if (a[n][0]==NULL && a[n][1]==NULL){
	
	printf ("This room is empty! ");
	return 0; 
	}
	//if (a[n,0]!=NULL && a[n,1]!=NULL)
	return a[n][0];
	
}
int get1 (n){

	//if (a[n,0]!=NULL && a[n,1]!=NULL)
	return a[n][1];
	
}



int main(int argc, char *argv[]) {
	
while(1){

int num ;
printf("\nEnter a number : ");
scanf("%d",&num);

int room = mod (num);
//printf("%d",room);    //mod denemesi

put (num,room);



printf ("Enter a room to get its number : ");
scanf("%d",&room);
printf("Number in this room : %d ",get(room));
	if (get1(room)!=0)
	printf ("and %d",get1(room));
	
	
	
	
	
	
	
}
	
	return 0;
}