Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - #include<stdio.h>
 - #include<malloc.h>
 - #include<string.h>
 - #define SIZE 10
 - struct emp
 - {
 - char name[20];
 - float salary;
 - int age;
 - struct emp *ptr;
 - };
 - struct emp *DICTIONARY[SIZE];
 - void null()
 - {
 - int i;
 - for(i=0;i<SIZE;i++)
 - {
 - DICTIONARY[i]=NULL;
 - }
 - }
 - int hash(int age)
 - {
 - return(age%SIZE);
 - }
 - void insert()
 - {
 - int n,i,age,key;
 - float sal;
 - char name[20];
 - printf("Enter the number of Employees");
 - scanf("%d",&n);
 - struct emp *newnode,*head;
 - for(i=0;i<n;i++)
 - {
 - printf(" \n Enter the age of the employee : ");
 - scanf("%d",&age);
 - key=hash(age);
 - printf("\n Enter the name of the employee : ");
 - scanf("%s",name);
 - printf("\n enter the salary of the employee : ");
 - scanf("%f",&sal);
 - head=DICTIONARY[key];
 - newnode=(struct emp *)malloc(sizeof(struct emp));
 - strcpy(newnode->name,name);
 - newnode->age=age;
 - newnode->salary=sal;
 - newnode->ptr=head;
 - DICTIONARY[key]=newnode;
 - }
 - }
 - void display()
 - {
 - int age,key;
 - float sum=0,average;
 - char name[20];
 - struct emp *temp;
 - printf("\n Enter the age of the employee to be searched : ");
 - scanf("%d",&age);
 - key=hash(age);
 - printf("\n Enter the employee name to be searched : ");
 - scanf("%s",name);
 - temp=DICTIONARY[key];
 - while(temp!=NULL)
 - {
 - if(strcmp(temp->name,name)==0)
 - break;
 - else
 - temp=temp->ptr;
 - }
 - if(temp==NULL)
 - {
 - printf("\n Employee not found ");
 - }
 - else
 - {
 - printf("\n the employee found");
 - printf("\n Name : %s",temp->name);
 - printf("\n age : %d",temp->age);
 - printf("\n salary: %f",temp->salary);
 - }
 - }
 - int main()
 - {
 - null();
 - insert();
 - display();
 - 1,1 Top
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment