hashtable linear probing ,insertion deletion searching

//all the basic opertaion insertion , deletion ,searching,displaying
#include <iostream>

using namespace std;
void init(int arr[],int size)
{
    for(int i=0;i<size;i++)
    {
        arr[i]=-1;
    }
}
void inserthash(int arr[],int size,int value)
{
    int key=value%size;
    int index=key;
    while(arr[index]!=-1)
    {
        index=(index+1)%size;
        if(index==key)
        {
            cout<<"hash table full"<<endl;
        }
    }
    arr[index]=value;
}
void deletehash(int arr[],int size,int value)
{
    int key=value%size;
    int index=key;
    while(arr[index]!=value)
    {
        index=(index+1)%size;
        if(index==key)
        {
            cout<<"value to be deleted not found"<<endl;
        }
    }
    arr[index]=-1;
}
int searchhash(int arr[],int size,int value)
{
    int key=value%size;
    int index=key;
    while(arr[index]!=value)
    {
        index=(index+1)%size;
        if(index==key)
        {
            return 0;
        }
    }
    return 1;

}
void display(int arr[],int size)
{
    for(int i=0;i<size;i++)
    {
        cout<<arr[i]<<" ";
    }
    cout<<endl;
}
int main()
{
    int n;
    cout<<"enter the size:"<<endl;
    cin>>n;
    int a[n];
    init(a,n);
    int choice;
    while(1)
    {
        cout<<"1. insert"<<endl<<"2.delete"<<endl<<"3.search"<<endl<<"4. display"<<endl<<"5. exit"<<endl;
       cout<<"enter the choice:"<<endl;
       cin>>choice;
       switch(choice)
       {
           case 1:
               {
                   int val;
                   cout<<"enter the value you want to insert:"<<endl;
                   cin>>val;
                   inserthash(a,n,val);
                   break;
               }
           case 2:
            {
                int val;
                cout<<"enter the value you want to delete:"<<endl;
                cin>>val;
                deletehash(a,n,val);
                break;
            }
           case 3:
            {
                int val;
                cout<<"enter the value to be searched:"<<endl;
                cin>>val;
                int l= searchhash(a,n,val);
                if(l==1)
                {
                    cout<<"value found"<<endl;
                }
                else
                {
                    cout<<"not found"<<endl;
                }
                break;
            }
           case 4:
            {
                display(a,n);
                break;
            }
           case 5:
            {
                exit(0);
            }
           default:
            {
                cout<<"invalid choice"<<endl;
            }
       }
    }
}

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source