Hashing 1

PHOTO EMBED

Mon Mar 06 2023 08:33:10 GMT+0000 (Coordinated Universal Time)

Saved by @saakshi #c++

#include<iostream>
using namespace std;
int main()
{
 int arr[10] = {0},key,c,d,ch=1;     //k = key, c = collision, d = data
 for(int i=0; i<=9 ; i++)
 {
  cout<<" "<<arr[i];
 }
 while(ch==1)
 {
  cout<<"\nEnter Key";
  cin>>key;
    c = 0;
  d = key % 10;
  for(int i=0;i<=9;i++)
  {
   if(arr[d]>0)
   {
    d++;
    c++;
   }
  }
  arr[d]  = key;
  for(int i=0;i<=9;i++)
  {
  cout<<arr[i]<<endl;;
  }
  cout<<"\nCollisions: "<<c;
  cout<<"Do you want to continue: ";
  cin>>ch;
 }

 return 0;
 }
content_copyCOPY

hashing simple code...without replacement