SlideShare a Scribd company logo
1 of 7
Download to read offline
Do the following program in C++
- Create a item class... with and integer key and value
- Create a Hash class, that has an array of can input a item and uses a hash algorithm to place it
in a array of item nodes.
Include the necessary functions...
-Use CHAINING with pointers, when there is a collision.
-Have a function that prints out the array to verify the hashing and collision code works...
Explain each entry you insert into the hash table...
Solution
#include
using namespace std;
const int TABLE_SIZE = 128;
/*
* HashNode Class Declaration
*/
class HashNode
{
public:
int key;
int value;
HashNode* next;
HashNode(int key, int value)
{
this->key = key;
this->value = value;
this->next = NULL;
}
};
/*
* HashMap Class Declaration
*/
class HashMap
{
private:
HashNode** htable;
public:
HashMap()
{
htable = new HashNode*[TABLE_SIZE];
for (int i = 0; i < TABLE_SIZE; i++)
htable[i] = NULL;
}
~HashMap()
{
for (int i = 0; i < TABLE_SIZE; ++i)
{
HashNode* entry = htable[i];
while (entry != NULL)
{
HashNode* prev = entry;
entry = entry->next;
delete prev;
}
}
delete[] htable;
}
/*
* Hash Function
*/
void Display()
{
for (int i = 0; i < TABLE_SIZE; ++i)
{
HashNode* entry = htable[i];
while (entry != NULL)
{
cout<<"Key "<key<<" Value "<value<next;
//delete prev;
}
}
}
int HashFunc(int key)
{
return key % TABLE_SIZE;
}
/*
* Insert Element at a key
*/
void Insert(int key, int value)
{
int hash_val = HashFunc(key);
HashNode* prev = NULL;
HashNode* entry = htable[hash_val];
while (entry != NULL)
{
prev = entry;
entry = entry->next;
}
if (entry == NULL)
{
entry = new HashNode(key, value);
if (prev == NULL)
{
htable[hash_val] = entry;
}
else
{
prev->next = entry;
}
}
else
{
entry->value = value;
}
}
/*
* Remove Element at a key
*/
void Remove(int key)
{
int hash_val = HashFunc(key);
HashNode* entry = htable[hash_val];
HashNode* prev = NULL;
if (entry == NULL || entry->key != key)
{
cout<<"No Element found at key "<next != NULL)
{
prev = entry;
entry = entry->next;
}
if (prev != NULL)
{
prev->next = entry->next;
}
delete entry;
cout<<"Element Deleted"<key == key)
{
cout<value<<" ";
flag = true;
}
entry = entry->next;
}
if (!flag)
return -1;
}
};
/*
* Main Contains Menu
*/
int main()
{
HashMap hash;
int key, value;
int choice;
while (1)
{
cout<<" ----------------------"<>choice;
switch(choice)
{
case 1:
cout<<"Enter element to be inserted: ";
cin>>value;
cout<<"Enter key at which element to be inserted: ";
cin>>key;
hash.Insert(key, value);
break;
case 2:
cout<<"Enter key of the element to be searched: ";
cin>>key;
cout<<"Element at key "<>key;
hash.Remove(key);
break;
case 4:
hash.Display();break;
case 5:
return 0;
default:
cout<<" Enter correct option ";
}
}
return 0;
}
==================================================================
Output:
akshay@akshay-Inspiron-3537:~/Chegg$ g++ hash.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
----------------------
Operations on Hash Table
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Display
5.Exit
Enter your choice: 1
Enter element to be inserted: 0
Enter key at which element to be inserted: 20
----------------------
Operations on Hash Table
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Display
5.Exit
Enter your choice: 1
Enter element to be inserted: 0
Enter key at which element to be inserted: 30
----------------------
Operations on Hash Table
----------------------
1.Insert element into the table
2.Search element from the key
3.Delete element at a key
4.Display
5.Exit
Enter your choice: 4
Key 20 Value 0
Key 30 Value 0
===================================================
In this code when we insert 20 value at key 0,then it will go correctly but when we try to insert
30 again at key 0,then it will create another node with 30 and attach next to 20 node.So that
Collision will be solved
=============================================================
Comment about work

More Related Content

Similar to Do the following program in C++- Create a item class... with and i.pdf

Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdfaathiauto
 
double linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdfdouble linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdffacevenky
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdfaathmaproducts
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
 
Php7 hashtable
Php7 hashtablePhp7 hashtable
Php7 hashtable桐 王
 
It is the main program that implement the min(), max(), floor(), cei.pdf
It is the main program that implement the min(), max(), floor(), cei.pdfIt is the main program that implement the min(), max(), floor(), cei.pdf
It is the main program that implement the min(), max(), floor(), cei.pdfannaindustries
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfankit11134
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfaassecuritysystem
 
ItemNodeh include ltiostreamgt include ltstring.pdf
ItemNodeh    include ltiostreamgt include ltstring.pdfItemNodeh    include ltiostreamgt include ltstring.pdf
ItemNodeh include ltiostreamgt include ltstring.pdfacmefit
 
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docxlab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docxDIPESH30
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1saydin_soft
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfHIMANSUKUMAR12
 
Program 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdfProgram 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdfezzi552
 
Implement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdfImplement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdfarihantstoneart
 
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfIn C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfstopgolook
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfallystraders
 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfamirthagiftsmadurai
 

Similar to Do the following program in C++- Create a item class... with and i.pdf (20)

Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdf
 
double linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdfdouble linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdf
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
Php7 hashtable
Php7 hashtablePhp7 hashtable
Php7 hashtable
 
It is the main program that implement the min(), max(), floor(), cei.pdf
It is the main program that implement the min(), max(), floor(), cei.pdfIt is the main program that implement the min(), max(), floor(), cei.pdf
It is the main program that implement the min(), max(), floor(), cei.pdf
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
 
ItemNodeh include ltiostreamgt include ltstring.pdf
ItemNodeh    include ltiostreamgt include ltstring.pdfItemNodeh    include ltiostreamgt include ltstring.pdf
ItemNodeh include ltiostreamgt include ltstring.pdf
 
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docxlab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
lab08build.bat@echo offclsset DRIVE_LETTER=1s.docx
 
Programs
ProgramsPrograms
Programs
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
Working With JQuery Part1
Working With JQuery Part1Working With JQuery Part1
Working With JQuery Part1
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
Program 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdfProgram 4You are to write an efficient program that will read a di.pdf
Program 4You are to write an efficient program that will read a di.pdf
 
Implement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdfImplement the unsorted single linked list as we did in the class and .pdf
Implement the unsorted single linked list as we did in the class and .pdf
 
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfIn C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
 
I have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdfI have created a class hasdhedDictionary that implements the Diction.pdf
I have created a class hasdhedDictionary that implements the Diction.pdf
 
using the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdfusing the code below write the public V add(K key, V value); that ad.pdf
using the code below write the public V add(K key, V value); that ad.pdf
 
week-14x
week-14xweek-14x
week-14x
 

More from ahntagencies

Mitosis promoting factor is associated with cyclin b. Which class of .pdf
Mitosis promoting factor is associated with cyclin b. Which class of .pdfMitosis promoting factor is associated with cyclin b. Which class of .pdf
Mitosis promoting factor is associated with cyclin b. Which class of .pdfahntagencies
 
LTE uses an all IP data network, with voice calls reduced to a multim.pdf
LTE uses an all IP data network, with voice calls reduced to a multim.pdfLTE uses an all IP data network, with voice calls reduced to a multim.pdf
LTE uses an all IP data network, with voice calls reduced to a multim.pdfahntagencies
 
I Need Serious Help with this assignment. Plenty Points to be earned.pdf
I Need Serious Help with this assignment. Plenty Points to be earned.pdfI Need Serious Help with this assignment. Plenty Points to be earned.pdf
I Need Serious Help with this assignment. Plenty Points to be earned.pdfahntagencies
 
I have code that reads and writes sstrings to file but I am having t.pdf
I have code that reads and writes sstrings to file but I am having t.pdfI have code that reads and writes sstrings to file but I am having t.pdf
I have code that reads and writes sstrings to file but I am having t.pdfahntagencies
 
Genes A and B are on different chromosomes. A dihybrid with the geno.pdf
Genes A and B are on different chromosomes. A dihybrid with the geno.pdfGenes A and B are on different chromosomes. A dihybrid with the geno.pdf
Genes A and B are on different chromosomes. A dihybrid with the geno.pdfahntagencies
 
Explain the process of RNAi and how it contributes to differential .pdf
Explain the process of RNAi and how it contributes to differential .pdfExplain the process of RNAi and how it contributes to differential .pdf
Explain the process of RNAi and how it contributes to differential .pdfahntagencies
 
Consider the following scenario A population of moderately pigmented.pdf
Consider the following scenario A population of moderately pigmented.pdfConsider the following scenario A population of moderately pigmented.pdf
Consider the following scenario A population of moderately pigmented.pdfahntagencies
 
Consider the simple analog signal defined by x(t) = sin(2700t) shown.pdf
Consider the simple analog signal defined by x(t) = sin(2700t) shown.pdfConsider the simple analog signal defined by x(t) = sin(2700t) shown.pdf
Consider the simple analog signal defined by x(t) = sin(2700t) shown.pdfahntagencies
 
Cell adhesion, both cell-cell and cell-ECM, can influence whether a c.pdf
Cell adhesion, both cell-cell and cell-ECM, can influence whether a c.pdfCell adhesion, both cell-cell and cell-ECM, can influence whether a c.pdf
Cell adhesion, both cell-cell and cell-ECM, can influence whether a c.pdfahntagencies
 
A(n) is a method of interacting with a PC by manipulating visual ele.pdf
A(n)  is a method of interacting with a PC by manipulating visual ele.pdfA(n)  is a method of interacting with a PC by manipulating visual ele.pdf
A(n) is a method of interacting with a PC by manipulating visual ele.pdfahntagencies
 
You are about to perform a clean install of Windows 7 on a brandnew .pdf
You are about to perform a clean install of Windows 7 on a brandnew .pdfYou are about to perform a clean install of Windows 7 on a brandnew .pdf
You are about to perform a clean install of Windows 7 on a brandnew .pdfahntagencies
 
Write the equation of a 4th degree polynomial function with the follo.pdf
Write the equation of a 4th degree polynomial function with the follo.pdfWrite the equation of a 4th degree polynomial function with the follo.pdf
Write the equation of a 4th degree polynomial function with the follo.pdfahntagencies
 
Write a program which repeatedly calls a function named replaceIt() a.pdf
Write a program which repeatedly calls a function named replaceIt() a.pdfWrite a program which repeatedly calls a function named replaceIt() a.pdf
Write a program which repeatedly calls a function named replaceIt() a.pdfahntagencies
 
Which, of the below choices of inference rules, is used to show that.pdf
Which, of the below choices of inference rules, is used to show that.pdfWhich, of the below choices of inference rules, is used to show that.pdf
Which, of the below choices of inference rules, is used to show that.pdfahntagencies
 
Which of the following protocols is used for router multicastingA.pdf
Which of the following protocols is used for router multicastingA.pdfWhich of the following protocols is used for router multicastingA.pdf
Which of the following protocols is used for router multicastingA.pdfahntagencies
 
Which of the following isare not produced by homosporous plants [se.pdf
Which of the following isare not produced by homosporous plants [se.pdfWhich of the following isare not produced by homosporous plants [se.pdf
Which of the following isare not produced by homosporous plants [se.pdfahntagencies
 
When Gregor Mendel was developing his ideas of inheritance of cha.pdf
When Gregor Mendel was developing his ideas of inheritance of cha.pdfWhen Gregor Mendel was developing his ideas of inheritance of cha.pdf
When Gregor Mendel was developing his ideas of inheritance of cha.pdfahntagencies
 
what kind of short tandem repeats DNA markers can be used for tracin.pdf
what kind of short tandem repeats DNA markers can be used for tracin.pdfwhat kind of short tandem repeats DNA markers can be used for tracin.pdf
what kind of short tandem repeats DNA markers can be used for tracin.pdfahntagencies
 
What is the job of a layout managerTo render user interface compo.pdf
What is the job of a layout managerTo render user interface compo.pdfWhat is the job of a layout managerTo render user interface compo.pdf
What is the job of a layout managerTo render user interface compo.pdfahntagencies
 
Using the Bernoulli method, solve the differential equation t^2 dyd.pdf
Using the Bernoulli method, solve the differential equation t^2 dyd.pdfUsing the Bernoulli method, solve the differential equation t^2 dyd.pdf
Using the Bernoulli method, solve the differential equation t^2 dyd.pdfahntagencies
 

More from ahntagencies (20)

Mitosis promoting factor is associated with cyclin b. Which class of .pdf
Mitosis promoting factor is associated with cyclin b. Which class of .pdfMitosis promoting factor is associated with cyclin b. Which class of .pdf
Mitosis promoting factor is associated with cyclin b. Which class of .pdf
 
LTE uses an all IP data network, with voice calls reduced to a multim.pdf
LTE uses an all IP data network, with voice calls reduced to a multim.pdfLTE uses an all IP data network, with voice calls reduced to a multim.pdf
LTE uses an all IP data network, with voice calls reduced to a multim.pdf
 
I Need Serious Help with this assignment. Plenty Points to be earned.pdf
I Need Serious Help with this assignment. Plenty Points to be earned.pdfI Need Serious Help with this assignment. Plenty Points to be earned.pdf
I Need Serious Help with this assignment. Plenty Points to be earned.pdf
 
I have code that reads and writes sstrings to file but I am having t.pdf
I have code that reads and writes sstrings to file but I am having t.pdfI have code that reads and writes sstrings to file but I am having t.pdf
I have code that reads and writes sstrings to file but I am having t.pdf
 
Genes A and B are on different chromosomes. A dihybrid with the geno.pdf
Genes A and B are on different chromosomes. A dihybrid with the geno.pdfGenes A and B are on different chromosomes. A dihybrid with the geno.pdf
Genes A and B are on different chromosomes. A dihybrid with the geno.pdf
 
Explain the process of RNAi and how it contributes to differential .pdf
Explain the process of RNAi and how it contributes to differential .pdfExplain the process of RNAi and how it contributes to differential .pdf
Explain the process of RNAi and how it contributes to differential .pdf
 
Consider the following scenario A population of moderately pigmented.pdf
Consider the following scenario A population of moderately pigmented.pdfConsider the following scenario A population of moderately pigmented.pdf
Consider the following scenario A population of moderately pigmented.pdf
 
Consider the simple analog signal defined by x(t) = sin(2700t) shown.pdf
Consider the simple analog signal defined by x(t) = sin(2700t) shown.pdfConsider the simple analog signal defined by x(t) = sin(2700t) shown.pdf
Consider the simple analog signal defined by x(t) = sin(2700t) shown.pdf
 
Cell adhesion, both cell-cell and cell-ECM, can influence whether a c.pdf
Cell adhesion, both cell-cell and cell-ECM, can influence whether a c.pdfCell adhesion, both cell-cell and cell-ECM, can influence whether a c.pdf
Cell adhesion, both cell-cell and cell-ECM, can influence whether a c.pdf
 
A(n) is a method of interacting with a PC by manipulating visual ele.pdf
A(n)  is a method of interacting with a PC by manipulating visual ele.pdfA(n)  is a method of interacting with a PC by manipulating visual ele.pdf
A(n) is a method of interacting with a PC by manipulating visual ele.pdf
 
You are about to perform a clean install of Windows 7 on a brandnew .pdf
You are about to perform a clean install of Windows 7 on a brandnew .pdfYou are about to perform a clean install of Windows 7 on a brandnew .pdf
You are about to perform a clean install of Windows 7 on a brandnew .pdf
 
Write the equation of a 4th degree polynomial function with the follo.pdf
Write the equation of a 4th degree polynomial function with the follo.pdfWrite the equation of a 4th degree polynomial function with the follo.pdf
Write the equation of a 4th degree polynomial function with the follo.pdf
 
Write a program which repeatedly calls a function named replaceIt() a.pdf
Write a program which repeatedly calls a function named replaceIt() a.pdfWrite a program which repeatedly calls a function named replaceIt() a.pdf
Write a program which repeatedly calls a function named replaceIt() a.pdf
 
Which, of the below choices of inference rules, is used to show that.pdf
Which, of the below choices of inference rules, is used to show that.pdfWhich, of the below choices of inference rules, is used to show that.pdf
Which, of the below choices of inference rules, is used to show that.pdf
 
Which of the following protocols is used for router multicastingA.pdf
Which of the following protocols is used for router multicastingA.pdfWhich of the following protocols is used for router multicastingA.pdf
Which of the following protocols is used for router multicastingA.pdf
 
Which of the following isare not produced by homosporous plants [se.pdf
Which of the following isare not produced by homosporous plants [se.pdfWhich of the following isare not produced by homosporous plants [se.pdf
Which of the following isare not produced by homosporous plants [se.pdf
 
When Gregor Mendel was developing his ideas of inheritance of cha.pdf
When Gregor Mendel was developing his ideas of inheritance of cha.pdfWhen Gregor Mendel was developing his ideas of inheritance of cha.pdf
When Gregor Mendel was developing his ideas of inheritance of cha.pdf
 
what kind of short tandem repeats DNA markers can be used for tracin.pdf
what kind of short tandem repeats DNA markers can be used for tracin.pdfwhat kind of short tandem repeats DNA markers can be used for tracin.pdf
what kind of short tandem repeats DNA markers can be used for tracin.pdf
 
What is the job of a layout managerTo render user interface compo.pdf
What is the job of a layout managerTo render user interface compo.pdfWhat is the job of a layout managerTo render user interface compo.pdf
What is the job of a layout managerTo render user interface compo.pdf
 
Using the Bernoulli method, solve the differential equation t^2 dyd.pdf
Using the Bernoulli method, solve the differential equation t^2 dyd.pdfUsing the Bernoulli method, solve the differential equation t^2 dyd.pdf
Using the Bernoulli method, solve the differential equation t^2 dyd.pdf
 

Recently uploaded

BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...Nguyen Thanh Tu Collection
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17Celine George
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxAdelaideRefugio
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 

Recently uploaded (20)

BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 

Do the following program in C++- Create a item class... with and i.pdf

  • 1. Do the following program in C++ - Create a item class... with and integer key and value - Create a Hash class, that has an array of can input a item and uses a hash algorithm to place it in a array of item nodes. Include the necessary functions... -Use CHAINING with pointers, when there is a collision. -Have a function that prints out the array to verify the hashing and collision code works... Explain each entry you insert into the hash table... Solution #include using namespace std; const int TABLE_SIZE = 128; /* * HashNode Class Declaration */ class HashNode { public: int key; int value; HashNode* next; HashNode(int key, int value) { this->key = key; this->value = value; this->next = NULL; } }; /* * HashMap Class Declaration
  • 2. */ class HashMap { private: HashNode** htable; public: HashMap() { htable = new HashNode*[TABLE_SIZE]; for (int i = 0; i < TABLE_SIZE; i++) htable[i] = NULL; } ~HashMap() { for (int i = 0; i < TABLE_SIZE; ++i) { HashNode* entry = htable[i]; while (entry != NULL) { HashNode* prev = entry; entry = entry->next; delete prev; } } delete[] htable; } /* * Hash Function */ void Display() { for (int i = 0; i < TABLE_SIZE; ++i) { HashNode* entry = htable[i]; while (entry != NULL) {
  • 3. cout<<"Key "<key<<" Value "<value<next; //delete prev; } } } int HashFunc(int key) { return key % TABLE_SIZE; } /* * Insert Element at a key */ void Insert(int key, int value) { int hash_val = HashFunc(key); HashNode* prev = NULL; HashNode* entry = htable[hash_val]; while (entry != NULL) { prev = entry; entry = entry->next; } if (entry == NULL) { entry = new HashNode(key, value); if (prev == NULL) { htable[hash_val] = entry; } else { prev->next = entry; } } else
  • 4. { entry->value = value; } } /* * Remove Element at a key */ void Remove(int key) { int hash_val = HashFunc(key); HashNode* entry = htable[hash_val]; HashNode* prev = NULL; if (entry == NULL || entry->key != key) { cout<<"No Element found at key "<next != NULL) { prev = entry; entry = entry->next; } if (prev != NULL) { prev->next = entry->next; } delete entry; cout<<"Element Deleted"<key == key) { cout<value<<" "; flag = true; } entry = entry->next; } if (!flag) return -1; } }; /*
  • 5. * Main Contains Menu */ int main() { HashMap hash; int key, value; int choice; while (1) { cout<<" ----------------------"<>choice; switch(choice) { case 1: cout<<"Enter element to be inserted: "; cin>>value; cout<<"Enter key at which element to be inserted: "; cin>>key; hash.Insert(key, value); break; case 2: cout<<"Enter key of the element to be searched: "; cin>>key; cout<<"Element at key "<>key; hash.Remove(key); break; case 4: hash.Display();break; case 5: return 0; default: cout<<" Enter correct option "; } } return 0; } ==================================================================
  • 6. Output: akshay@akshay-Inspiron-3537:~/Chegg$ g++ hash.cpp akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out ---------------------- Operations on Hash Table ---------------------- 1.Insert element into the table 2.Search element from the key 3.Delete element at a key 4.Display 5.Exit Enter your choice: 1 Enter element to be inserted: 0 Enter key at which element to be inserted: 20 ---------------------- Operations on Hash Table ---------------------- 1.Insert element into the table 2.Search element from the key 3.Delete element at a key 4.Display 5.Exit Enter your choice: 1 Enter element to be inserted: 0 Enter key at which element to be inserted: 30 ---------------------- Operations on Hash Table ---------------------- 1.Insert element into the table 2.Search element from the key 3.Delete element at a key 4.Display 5.Exit Enter your choice: 4 Key 20 Value 0 Key 30 Value 0
  • 7. =================================================== In this code when we insert 20 value at key 0,then it will go correctly but when we try to insert 30 again at key 0,then it will create another node with 30 and attach next to 20 node.So that Collision will be solved ============================================================= Comment about work