You are on page 1of 2

#include<stdio.h> #include<stdlib.h> #include<string.

h> #define MAX 7 struct hashentry { int key; char name[10]; //int del; }table[MAX]; typedef struct hashentry entry; int func( int key) { int value= key%MAX; return value; } void insert(int k, const char* a) { int i; int h2=0; int h1=func(k); if(table[h1].key==-1) { table[h1].key=k; strcpy(table[h1].name,a); } else { i=1; while(table[h2].key!=-1) { h2=(h1+i)%MAX; i++; if(i>=MAX) { printf("\n out of space!"); exit(1); } } table[h2].key=k; strcpy(table[h2].name,a); } }// end func void display() { int i; for(i=0;i<MAX;i++) { printf("\n%d %s",table[i].key,table[i].name); } } int main() {

int i; for(i=0;i<MAX;i++) { table[i].key=-1; //table[i].name="q"; }

insert(2,"a"); insert(6,"b"); insert(5,"c"); insert(8,"d"); insert(11,"e"); display(); //return 0; }