#include<stdio.h> #include<conio.h> #include<stdlib.h> #define n 10 //Linear Probing void insert(int arr[]) { int i=1; int item,pos; int inserted=0; printf("Enter Item : "); scanf("%d",&item); pos=item%10; while(i<=10) { if(arr[pos]==-1) { arr[pos]=item; inserted=1; break; } else { pos=(pos+1)%n; } i++; } if(!inserted) printf("Overflow"); } void search(int arr[]) { int i=1,item,pos,found=0; printf("Enter item to be searched : "); scanf("%d",&item); pos=item%10; while(i<=10) { if(arr[pos]==item) { printf("Found"); found=1; break; } else pos=(pos+1)%n; i++; } if(!found) printf("Not Found"); } void display(int arr[]) { int i; for(i=0;i<n;i++) { if(arr[i]!=-1) printf("\n%d",arr[i]); else printf("\nNULL"); } } void delete(int arr[]) { int i=1,item,pos,deleted=0; printf("Enter item to be deleted : "); scanf("%d",&item); pos=item%10; while(i<=10) { if(arr[pos]==item) { printf("Deleted Successfully "); arr[pos]=-1; deleted=1; break; } else pos=(pos+1)%n; i++; } if(!delete) printf("Not Found"); } void main() { int arr[n]={-1}; int ch; int i; clrscr(); for( i=0;i<10;i++) { arr[i]=-1; } while(1) { printf("\n1. Insert"); printf("\n2. Search"); printf("\n3. Display"); printf("\n4. Delete"); printf("\n5. Exit"); printf("\nEnter Your Choice : "); scanf("%d",&ch); if(ch==1) insert(arr); else if(ch==2) search(arr); else if(ch==3) display(arr); else if(ch==4) delete(arr); else if(ch==5) break; else printf("Invalid Choice"); } getch(); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter