SlideShare a Scribd company logo
//Let n = size of the hash table
// hashTable = array of size n, which represents the hash table
// hashIndex = represents the index of array
// If the list is EMPTY, we add the element into the list
/*If the list is NOT EMPTY then we compare the newNode to the node already in the list in such
a way to get sorted.*/
struct node
{
int key;
T value;
struct node *next;
};
struct node *hashTable[n] = {NULL};
struct node * createNode(int key, char *name, int age)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->value = value;
newnode->next = NULL;
return newnode;
}
add(int key, T value)
{
int hashIndex = key % n;
struct node *newNode = creteNode(key,value);
/*Adding new node to the list with No element */
if (hashTable[hashIndex] == NULL)
{
hashTable[hashIndex] = newnode;
return;
}
/*Adding new node to the sorted list */
struct node *temp1;
struct node *temp2 = hashTable[hashIndex];
temp1 = temp2;
while(temp2 -> key < newNode -> key)
{
temp1 = temp2;
temp2 = temp2 ->next;
}
newnode->next = temp2;
temp1->next = newNode;
return;
}
Solution
//Let n = size of the hash table
// hashTable = array of size n, which represents the hash table
// hashIndex = represents the index of array
// If the list is EMPTY, we add the element into the list
/*If the list is NOT EMPTY then we compare the newNode to the node already in the list in such
a way to get sorted.*/
struct node
{
int key;
T value;
struct node *next;
};
struct node *hashTable[n] = {NULL};
struct node * createNode(int key, char *name, int age)
{
struct node *newnode;
newnode = (struct node *)malloc(sizeof(struct node));
newnode->key = key;
newnode->value = value;
newnode->next = NULL;
return newnode;
}
add(int key, T value)
{
int hashIndex = key % n;
struct node *newNode = creteNode(key,value);
/*Adding new node to the list with No element */
if (hashTable[hashIndex] == NULL)
{
hashTable[hashIndex] = newnode;
return;
}
/*Adding new node to the sorted list */
struct node *temp1;
struct node *temp2 = hashTable[hashIndex];
temp1 = temp2;
while(temp2 -> key < newNode -> key)
{
temp1 = temp2;
temp2 = temp2 ->next;
}
newnode->next = temp2;
temp1->next = newNode;
return;
}

More Related Content

Similar to Let n = size of the hash table hashTable = array of size n, w.pdf (20)

PDF
Advanced data structures vol. 1
Christalin Nelson
 
PDF
My C proggram is having trouble in the switch in main. Also the a co.pdf
meerobertsonheyde608
 
DOCX
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
GordonpACKellyb
 
PPTX
Working with python Nice PPT must try very good
MuhammadChala
 
PPTX
DSA Presentation of Data Structures and Algorithms.pptx
haseebanjum2611
 
PPTX
Data structures and algorithms lab11
Bianca Teşilă
 
PPTX
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
 
PPT
Data Structures 7
Dr.Umadevi V
 
PDF
Implementing virtual machines in go & c 2018 redux
Eleanor McHugh
 
DOCX
(C++ exercise) 1.Implement a circular, doubly linked list with a has.docx
ajoy21
 
PDF
Hash table
Abdelrahman Saleh
 
DOCX
Data Structures Using C Practical File
Rahul Chugh
 
PDF
C언어 스터디 강의자료 - 5차시
Junha Jang
 
PPTX
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
mohanrajm63
 
DOCX
(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx
ajoy21
 
PDF
DSA.pdf
Rishab Saini
 
PPTX
Intro to Hash tables
Amy Hua
 
PDF
hashing.pdf
Yuvraj919347
 
PPT
4.4 hashing02
Krish_ver2
 
PPTX
Sorting and hashing concepts
LJ Projects
 
Advanced data structures vol. 1
Christalin Nelson
 
My C proggram is having trouble in the switch in main. Also the a co.pdf
meerobertsonheyde608
 
IN C LANGUAGE- I've been trying to finish this program for the last fe.docx
GordonpACKellyb
 
Working with python Nice PPT must try very good
MuhammadChala
 
DSA Presentation of Data Structures and Algorithms.pptx
haseebanjum2611
 
Data structures and algorithms lab11
Bianca Teşilă
 
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
 
Data Structures 7
Dr.Umadevi V
 
Implementing virtual machines in go & c 2018 redux
Eleanor McHugh
 
(C++ exercise) 1.Implement a circular, doubly linked list with a has.docx
ajoy21
 
Hash table
Abdelrahman Saleh
 
Data Structures Using C Practical File
Rahul Chugh
 
C언어 스터디 강의자료 - 5차시
Junha Jang
 
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
mohanrajm63
 
(C++ exercise) 3. Implement a circular, doubly linked list with a ha.docx
ajoy21
 
DSA.pdf
Rishab Saini
 
Intro to Hash tables
Amy Hua
 
hashing.pdf
Yuvraj919347
 
4.4 hashing02
Krish_ver2
 
Sorting and hashing concepts
LJ Projects
 

More from aravlitraders2012 (20)

PDF
Exception to indicate that Singly LinkedList is empty. .pdf
aravlitraders2012
 
PDF
Electronegativity - Electronegativity is an atom.pdf
aravlitraders2012
 
PDF
Sequence.h#ifndef MAIN #define MAIN #include cstdlibclass .pdf
aravlitraders2012
 
PDF
In the 1st Question, As the polymorphisms occur in the non-coding se.pdf
aravlitraders2012
 
PDF
I noticed that temperature is not mentioned. A) .pdf
aravlitraders2012
 
PDF
1. Briefly describe the structured design approach and the object-or.pdf
aravlitraders2012
 
PDF
1) Protocols are needed so your computer can interact with other com.pdf
aravlitraders2012
 
PDF
argon is inert gas , doesnot chemically reacts wi.pdf
aravlitraders2012
 
PDF
#include sstream #include linkylist.h #include iostream.pdf
aravlitraders2012
 
PDF
Function header If a program contain a function definition, that .pdf
aravlitraders2012
 
PDF
GameOfLife.cs using System; using System.Collections.Generic;.pdf
aravlitraders2012
 
PDF
With the vast increase in technology, the number of ways that the us.pdf
aravlitraders2012
 
PDF
What is the need of the t Distribution According to the central.pdf
aravlitraders2012
 
PDF
We can see in course of evolution of plant there was a transition fr.pdf
aravlitraders2012
 
PDF
Wave CharacterMany of the things that light does are only expla.pdf
aravlitraders2012
 
PDF
The solvent doesnt interfere with the purification processOil Bath.pdf
aravlitraders2012
 
PDF
An object of class StatCalc can be used to compute several simp.pdf
aravlitraders2012
 
PDF
The answers can be found below as discussedPart 1)The human gen.pdf
aravlitraders2012
 
PDF
Solution (3)The smallest respiratory bronchioles subdivide into t.pdf
aravlitraders2012
 
PDF
An asset manager of a hedge fund or a mutual funds is the one who di.pdf
aravlitraders2012
 
Exception to indicate that Singly LinkedList is empty. .pdf
aravlitraders2012
 
Electronegativity - Electronegativity is an atom.pdf
aravlitraders2012
 
Sequence.h#ifndef MAIN #define MAIN #include cstdlibclass .pdf
aravlitraders2012
 
In the 1st Question, As the polymorphisms occur in the non-coding se.pdf
aravlitraders2012
 
I noticed that temperature is not mentioned. A) .pdf
aravlitraders2012
 
1. Briefly describe the structured design approach and the object-or.pdf
aravlitraders2012
 
1) Protocols are needed so your computer can interact with other com.pdf
aravlitraders2012
 
argon is inert gas , doesnot chemically reacts wi.pdf
aravlitraders2012
 
#include sstream #include linkylist.h #include iostream.pdf
aravlitraders2012
 
Function header If a program contain a function definition, that .pdf
aravlitraders2012
 
GameOfLife.cs using System; using System.Collections.Generic;.pdf
aravlitraders2012
 
With the vast increase in technology, the number of ways that the us.pdf
aravlitraders2012
 
What is the need of the t Distribution According to the central.pdf
aravlitraders2012
 
We can see in course of evolution of plant there was a transition fr.pdf
aravlitraders2012
 
Wave CharacterMany of the things that light does are only expla.pdf
aravlitraders2012
 
The solvent doesnt interfere with the purification processOil Bath.pdf
aravlitraders2012
 
An object of class StatCalc can be used to compute several simp.pdf
aravlitraders2012
 
The answers can be found below as discussedPart 1)The human gen.pdf
aravlitraders2012
 
Solution (3)The smallest respiratory bronchioles subdivide into t.pdf
aravlitraders2012
 
An asset manager of a hedge fund or a mutual funds is the one who di.pdf
aravlitraders2012
 

Recently uploaded (20)

PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
PPTX
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PPTX
ENGlish 8 lesson presentation PowerPoint.pptx
marawehsvinetshe
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPTX
infertility, types,causes, impact, and management
Ritu480198
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
epi editorial commitee meeting presentation
MIPLM
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
STATEMENT-BY-THE-HON.-MINISTER-FOR-HEALTH-ON-THE-COVID-19-OUTBREAK-AT-UG_revi...
nservice241
 
SD_GMRC5_Session 6AB_Dulog Pedagohikal at Pagtataya (1).pptx
NickeyArguelles
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
DAY 1_QUARTER1 ENGLISH 5 WEEK- PRESENTATION.pptx
BanyMacalintal
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
ENGlish 8 lesson presentation PowerPoint.pptx
marawehsvinetshe
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
infertility, types,causes, impact, and management
Ritu480198
 
Introduction presentation of the patentbutler tool
MIPLM
 

Let n = size of the hash table hashTable = array of size n, w.pdf

  • 1. //Let n = size of the hash table // hashTable = array of size n, which represents the hash table // hashIndex = represents the index of array // If the list is EMPTY, we add the element into the list /*If the list is NOT EMPTY then we compare the newNode to the node already in the list in such a way to get sorted.*/ struct node { int key; T value; struct node *next; }; struct node *hashTable[n] = {NULL}; struct node * createNode(int key, char *name, int age) { struct node *newnode; newnode = (struct node *)malloc(sizeof(struct node)); newnode->key = key; newnode->value = value; newnode->next = NULL; return newnode; } add(int key, T value) { int hashIndex = key % n; struct node *newNode = creteNode(key,value); /*Adding new node to the list with No element */ if (hashTable[hashIndex] == NULL) { hashTable[hashIndex] = newnode; return;
  • 2. } /*Adding new node to the sorted list */ struct node *temp1; struct node *temp2 = hashTable[hashIndex]; temp1 = temp2; while(temp2 -> key < newNode -> key) { temp1 = temp2; temp2 = temp2 ->next; } newnode->next = temp2; temp1->next = newNode; return; } Solution //Let n = size of the hash table // hashTable = array of size n, which represents the hash table // hashIndex = represents the index of array // If the list is EMPTY, we add the element into the list /*If the list is NOT EMPTY then we compare the newNode to the node already in the list in such a way to get sorted.*/ struct node { int key; T value; struct node *next; }; struct node *hashTable[n] = {NULL}; struct node * createNode(int key, char *name, int age) { struct node *newnode;
  • 3. newnode = (struct node *)malloc(sizeof(struct node)); newnode->key = key; newnode->value = value; newnode->next = NULL; return newnode; } add(int key, T value) { int hashIndex = key % n; struct node *newNode = creteNode(key,value); /*Adding new node to the list with No element */ if (hashTable[hashIndex] == NULL) { hashTable[hashIndex] = newnode; return; } /*Adding new node to the sorted list */ struct node *temp1; struct node *temp2 = hashTable[hashIndex]; temp1 = temp2; while(temp2 -> key < newNode -> key) { temp1 = temp2; temp2 = temp2 ->next; } newnode->next = temp2; temp1->next = newNode; return; }