"open hashing basic operations" Code Answer's

You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "open hashing basic operations" answered properly. Developers are finding an appropriate answer about open hashing basic operations related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like open hashing basic operations. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on open hashing basic operations. 

open hashing basic operations

By ujjwal sotraujjwal sotra on May 24, 2021
//open hashing , insertion,deletion,searching,displaying
#include <iostream>

using namespace std;
#define n 5
class node
{
public:
    int data;
    node*next;
};
node*hasharray[n];
void init()
{
    for(int i=0;i<n;i++)
    {
        hasharray[i]=NULL;
    }
}
void addhash(int value)
{
    node *temp=new node;
    int key=value%n;
    temp->data=value;
    temp->next=hasharray[key];
    hasharray[key]=temp;
}
int deletehash(int value)
{
    node *temp=new node;
    node*ptr=new node;
    int key=value%n;
    temp=hasharray[key];
    if(temp!=NULL)
    {
        if(temp->data==value)
        {
            ptr=temp;
            hasharray[key]=hasharray[key]->next;
            delete ptr;
            return 1;
        }
        else
        {
            while(temp->next!=NULL)
            {
                if(temp->next->data==value)
                {
                    ptr=temp->next;
                    temp->next=temp->next->next;
                    delete ptr;
                    return 1;
                }
            }
        }
    }
    return 0;
}
int searchhash(int value)
{
    int key=value%n;
    node *temp=new node;
    temp=hasharray[key];
    while(temp!=NULL)
    {
        if(temp->data==value)
        {
            return 1;
        }
        temp=temp->next;
    }
    return 0;
}
void display()
{
    for(int i=0;i<n;i++)
    {
        node *temp=new node;
        temp=hasharray[i];
        cout<<"hasharray"<<"["<<i<<"]"<<endl;
        while(temp!=NULL)
        {
            cout<<temp->data<<" ";
            temp=temp->next;
        }
        cout<<endl;
    }
}

int main()
{
    init();
    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;
                addhash(val);
                break;
            }
        case 2:
            {
               int val;
               cout<<"enter the value you want to delete:"<<endl;
               cin>>val;
               int l=deletehash(val);
               if(l==1)
               {
                   cout<<"value deleted"<<endl;
               }
               else
               {
                   cout<<"value not found to be deleted"<<endl;
               }
               break;
            }
        case 3:
            {
              int val;
              cout<<"enter the value to be searched:"<<endl;
              cin>>val;
              int l=searchhash(val);
              if(l==1)
              {
                  cout<<"value found in hash table:"<<endl;
              }
              else
              {
                  cout<<"value not present"<<endl;
              }
              break;
            }
        case 4:
            {
                display();
                break;
            }
        case 5:
            {
                exit(0);

            }
        default:
            {
                cout<<"wrong choice :"<<endl;
                cout<<"--------------------------------------------"<<endl<<"please select between 1-5"<<endl;
                break;
            }
        }
    }

    return 0;
}

Add Comment

0

All those coders who are working on the C++ based application and are stuck on open hashing basic operations can get a collection of related answers to their query. Programmers need to enter their query on open hashing basic operations related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about open hashing basic operations for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of open hashing basic operations while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "open hashing basic operations". Visit this developer's friendly online web community, CodeProZone, and get your queries like open hashing basic operations resolved professionally and stay updated to the latest C++ updates. 

C++ answers related to "open hashing basic operations"

View All C++ queries

C++ queries related to "open hashing basic operations"

Browse Other Code Languages

CodeProZone