Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- #define m 11
- #define n 10
- #define nullkey -1
- int arr[6] = {32,15,25,44,36,21};
- struct node
- {
- int key;
- node *pnext;
- }; node *hashtable1[m];
- void clear()
- {
- for (int i = 0; i < m; i++)
- {
- hashtable1[i] = NULL;
- }
- }
- int key(int x)
- {
- return x % n;
- }
- void in()
- {
- node *p;
- for (int i = 0; i < m; i++)
- {
- cout << endl;
- cout << "[" << i << "]" << " ";
- p = hashtable1[i];
- if (p == NULL)
- cout << "null";
- while (p != NULL)
- {
- cout << p->key <<" ";
- p = p->pnext;
- }
- }
- }
- void insert(int data,int list)
- {
- node *newitem;
- newitem = new node;
- if (newitem == NULL)
- return;
- newitem->key = data;
- newitem->pnext = NULL;
- if (hashtable1[list] == NULL)
- {
- hashtable1[list] = newitem;
- }
- else
- {
- newitem->pnext = hashtable1[list];
- hashtable1[list] = newitem;
- }
- }
- void inset(int arr[])
- {
- for (int i = 0; i < 6; i++)
- {
- int b = key(arr[i]);
- insert(arr[i], b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement