-
Notifications
You must be signed in to change notification settings - Fork 64
/
code of Hashing in C++.cpp
57 lines (49 loc) · 1.1 KB
/
code of Hashing in C++.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// DATA STRUCTURES.cpp
//
// Created by Prince Kumar on 14/08/2020.
// Copyright © 2020 Prince Kumar. All rights reserved.
//
// ---** TREE DATA STRUCTURE in C++ **---
// ---** PRACTICE CODING SKILLS **---
#include <iostream>
#include <math.h>
using namespace std;
#define MAX 1000
bool hashTable[MAX+1][2];
bool search(int x){
if(x>=0){
if(hashTable[x][0] == 1 ){
return true;
}else{
return false;
}
}else{
x = abs(x);
if(hashTable[x][1] == 1 ){
return true;
}else{
return false;
}
}
}
void insert(int a[], int n){
for(int i=0;i<n;i++ ){
if(a[i]>=0){
hashTable[a[i]][0] = 1;
}
else{
hashTable[abs(a[i])][1] = 1;
}
}
}
int main(){
int arr[] = {-1, 9, 2, -5, 3, 1};
int n = sizeof(arr)/sizeof(arr[0]);
insert(arr, n);
int find = -1;
if(search(find)){
cout<<"Element is present"<<endl;
}else{
cout<<"Element is not present "<<endl;
}
}