#include <iostream>
using namespace std;
struct Node
{
int data;
Node *next;
};
class ch
{
private:
Node *first;
int Size;
public:
//constructor
ch(int size)
{
Size=size;
first=new Node [size];
for (int i=0; i<size; i++)
{
first[i]=NULL;
}
}
//hash Function
int hash(int value)
{
return (value%Size);
}
//insert function
void insert(int value)
{
int location=hash(value);
Node *temp=new Node;
temp->data=value;
temp->next=first[location];
first[location]=temp;
}
//search Function
bool search(int value)
{
int location=hash(value);
if (first[location]==NULL)
{
return false;
}
else
{
Node *ptr=first[location];
while (ptr->next!=NULL)
{
if (ptr->data==value)
{
break;
}
else
{
ptr=ptr->next;
}
}
if (ptr->next==NULL)
{
return false;
}
else
{
return true;
}
}
}
// delete fucntion
int del(int value)
{
int location=hash(value);
if (first[location]==NULL)
{
return -1
}
else
{
Node *pre=first[location],*curr=first[location];
while (curr->nex!=NULL)
{
if (curr->data==value)
{
break;
}
else
{
pre=curr;
curr=curr->next;
}
}
if (curr->next==NULL)
{
return -1;
}
else
{
int data=curr->data;
prev->next=curr->nex;
delete curr;
return data;
}
}
}
};
using namespace std;
struct Node
{
int data;
Node *next;
};
class ch
{
private:
Node *first;
int Size;
public:
//constructor
ch(int size)
{
Size=size;
first=new Node [size];
for (int i=0; i<size; i++)
{
first[i]=NULL;
}
}
//hash Function
int hash(int value)
{
return (value%Size);
}
//insert function
void insert(int value)
{
int location=hash(value);
Node *temp=new Node;
temp->data=value;
temp->next=first[location];
first[location]=temp;
}
//search Function
bool search(int value)
{
int location=hash(value);
if (first[location]==NULL)
{
return false;
}
else
{
Node *ptr=first[location];
while (ptr->next!=NULL)
{
if (ptr->data==value)
{
break;
}
else
{
ptr=ptr->next;
}
}
if (ptr->next==NULL)
{
return false;
}
else
{
return true;
}
}
}
// delete fucntion
int del(int value)
{
int location=hash(value);
if (first[location]==NULL)
{
return -1
}
else
{
Node *pre=first[location],*curr=first[location];
while (curr->nex!=NULL)
{
if (curr->data==value)
{
break;
}
else
{
pre=curr;
curr=curr->next;
}
}
if (curr->next==NULL)
{
return -1;
}
else
{
int data=curr->data;
prev->next=curr->nex;
delete curr;
return data;
}
}
}
};