SlideShare a Scribd company logo
1 of 6
Download to read offline
# [Gavin Lewis]
# P9 - Employee Hash Table
# The Hash Dictionary points to the first element of the Employee Linked List with its hash (0-
11)
class HashDictionary:
def __init__(self, hashLength):
self.beginChain = []
self.endChain = []
for n in range(hashLength):
self.beginChain.append(None)
self.endChain.append(None)
# Employee Linked List
class Employee:
def __init__(self, empID, empLastName, empFirstName, empPhone):
self.empID = empID
self.LastName = empLastName
self.FirstName = empFirstName
self.phone = empPhone
self.nextEmployee = None # corrected variable name
self.deleted = False # added deleted flag to mark deleted employees
def __str__(self): # added string representation for Employee
return "Employee ID: {}, Last Name: {}, First Name: {}, Phone: {}".format(
self.empID, self.LastName, self.FirstName, self.phone)
class EmployeeHashTable:
def __init__(self, hashLength):
self.hashDict = HashDictionary(hashLength)
def insertEmployee(self, empID, empLastName, empFirstName, empPhone):
position = empID % 12
currentNode = self.hashDict.beginChain[position]
prevNode = None
while currentNode is not None:
prevNode = currentNode
currentNode = currentNode.nextEmployee
emp = Employee(empID, empLastName, empFirstName, empPhone)
if prevNode is None:
self.hashDict.beginChain[position] = emp
else:
prevNode.nextEmployee = emp
print("Employee with ID {} added to database".format(emp.empID))
def searchEmployee(self, empID):
position = empID % 12
currentNode = self.hashDict.beginChain[position]
while currentNode is not None:
if currentNode.empID == empID and not currentNode.deleted: # check for deleted flag
print("Employee Found:n", currentNode)
return currentNode
currentNode = currentNode.nextEmployee
print("Employee with ID {} not found".format(empID))
return None
def deleteEmployee(self, empID):
position = empID % 12
currentNode = self.hashDict.beginChain[position]
while currentNode is not None:
if currentNode.empID == empID and not currentNode.deleted: # check for deleted flag
currentNode.deleted = True
print("Employee with ID {} marked as deleted".format(empID))
return
currentNode = currentNode.nextEmployee
print("Employee with ID {} not found".format(empID))
def traverseChain(self, startEMP):
print("Employee Chain:")
print(" ", startEMP)
node = startEMP.nextEmployee
while node is not None:
print(" ", node)
node = node.nextEmployee
# main program
from random import randint
import csv
hashLength = 12
empList = []
file = open('EmployeeDB.csv')
csvreader = csv.reader(file)
header = next(csvreader)
for employee in csvreader:
empList.append(employee)
HD = HashDictionary(hashLength)
for empRecord in empList:
empID = int(empRecord[0])
empLastName = empRecord[1]
empFirstName = empRecord[2]
empPhone = empRecord[3]
EMP = Employee(empID, empLastName, empFirstName, empPhone)
HD.insertEmployee(EMP)
empIDin = input("Enter Employee ID (001-999, 0 to Exit): ")
empID = int(empIDin)
while (empID > 0 and empID < 1000):
oper = input("Enter Operation Type (S)earch, (I)nsert, (D)elete: ")
if (oper == "S"):
E = HD.searchEmployee(empID)
if (E != None):
print(E.empID, E.FirstName, E.LastName, E.phone)
else:
print(empID, " Doesn't Exist")
elif (oper == "I"):
E = HD.searchEmployee(empID)
if (E != None):
print (empID, " Already Exists.", E.LastName, " Cannot Have Duplicates")
else:
fName = input("Enter Employee First Name: ")
lName = input("Enter Employee Last Name: ")
phoneNum = input("Enter Employee Phone Number: ")
EMP = Employee(empID, lName, fName, phoneNum)
HD.insertEmployee(EMP)
print (EMP.empID, EMP.LastName, " Record Inserted")
elif (oper == "D"):
E = HD.searchEmployee(empID)
if (E != None):
HD.deleteEmployee(empID, E)
print (E.empID, E.LastName, " Deleted")
else:
print(empID, " Not Found. Cannot Delete")
empIDin = input("Enter Employee ID (001-999, 0 to Exit): ")
empID = int(empIDin)
for n in range(hashLength):
print (n)
if (HD.beginChain[n] != None):
traverseChain(HD.beginChain[n])

More Related Content

Similar to # -Gavin Lewis- # P9 - Employee Hash Table # The Hash Dictionary poi.pdf

I need help in parse additional types of expressions defined by the ex.pdf
I need help in parse additional types of expressions defined by the ex.pdfI need help in parse additional types of expressions defined by the ex.pdf
I need help in parse additional types of expressions defined by the ex.pdfshreeaadithyaacellso
ย 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docxBlake0FxCampbelld
ย 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland
ย 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESIsmail Mukiibi
ย 
from datetime import datetime def CreateUsers()- print('##### Crea.pdf
from datetime import datetime def CreateUsers()-     print('##### Crea.pdffrom datetime import datetime def CreateUsers()-     print('##### Crea.pdf
from datetime import datetime def CreateUsers()- print('##### Crea.pdfatozworkwear
ย 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdffortmdu
ย 
Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfrajkumarm401
ย 
Tres Gemas De Ruby
Tres Gemas De RubyTres Gemas De Ruby
Tres Gemas De RubyLeonardo Soto
ย 
REST API Design for SQL developers
REST API Design for SQL developersREST API Design for SQL developers
REST API Design for SQL developersApigee | Google Cloud
ย 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
ย 
ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxjeyel85227
ย 
I need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfI need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfkourystephaniamari30
ย 
4.3 Hibernate example.docx
4.3 Hibernate example.docx4.3 Hibernate example.docx
4.3 Hibernate example.docxyasothamohankumar
ย 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab PracticeMahmud Hasan Tanvir
ย 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfvishalateen
ย 

Similar to # -Gavin Lewis- # P9 - Employee Hash Table # The Hash Dictionary poi.pdf (20)

I need help in parse additional types of expressions defined by the ex.pdf
I need help in parse additional types of expressions defined by the ex.pdfI need help in parse additional types of expressions defined by the ex.pdf
I need help in parse additional types of expressions defined by the ex.pdf
ย 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
ย 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
ย 
Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
ย 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
ย 
from datetime import datetime def CreateUsers()- print('##### Crea.pdf
from datetime import datetime def CreateUsers()-     print('##### Crea.pdffrom datetime import datetime def CreateUsers()-     print('##### Crea.pdf
from datetime import datetime def CreateUsers()- print('##### Crea.pdf
ย 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
ย 
Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdf
ย 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
ย 
Tres Gemas De Ruby
Tres Gemas De RubyTres Gemas De Ruby
Tres Gemas De Ruby
ย 
REST API Design for SQL developers
REST API Design for SQL developersREST API Design for SQL developers
REST API Design for SQL developers
ย 
REST for SQL Developers
REST for SQL DevelopersREST for SQL Developers
REST for SQL Developers
ย 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
ย 
Python : Dictionaries
Python : DictionariesPython : Dictionaries
Python : Dictionaries
ย 
ANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptxANSHUL RANA - PROGRAM FILE.pptx
ANSHUL RANA - PROGRAM FILE.pptx
ย 
I need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdfI need help with this two methods in java. Here are the guidelines. .pdf
I need help with this two methods in java. Here are the guidelines. .pdf
ย 
PHPLinq
PHPLinqPHPLinq
PHPLinq
ย 
4.3 Hibernate example.docx
4.3 Hibernate example.docx4.3 Hibernate example.docx
4.3 Hibernate example.docx
ย 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
ย 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
ย 

More from theyellowgold

(1 point) Suppose that X is normally distributed with mean 120 and sta.pdf
(1 point) Suppose that X is normally distributed with mean 120 and sta.pdf(1 point) Suppose that X is normally distributed with mean 120 and sta.pdf
(1 point) Suppose that X is normally distributed with mean 120 and sta.pdftheyellowgold
ย 
(1 point) Suppose we apply the Mix Columns operation to a -column- vec.pdf
(1 point) Suppose we apply the Mix Columns operation to a -column- vec.pdf(1 point) Suppose we apply the Mix Columns operation to a -column- vec.pdf
(1 point) Suppose we apply the Mix Columns operation to a -column- vec.pdftheyellowgold
ย 
#9 - Selective Repeat ARQ Protocol X attempts to send four frames (f0-.pdf
#9 - Selective Repeat ARQ Protocol X attempts to send four frames (f0-.pdf#9 - Selective Repeat ARQ Protocol X attempts to send four frames (f0-.pdf
#9 - Selective Repeat ARQ Protocol X attempts to send four frames (f0-.pdftheyellowgold
ย 
#2 A Treasury bond that matures in 10 years has a yield of 4-25-- A 10.pdf
#2 A Treasury bond that matures in 10 years has a yield of 4-25-- A 10.pdf#2 A Treasury bond that matures in 10 years has a yield of 4-25-- A 10.pdf
#2 A Treasury bond that matures in 10 years has a yield of 4-25-- A 10.pdftheyellowgold
ย 
(0) L Utunled er- fon Rouacin- Feceta Fenerm teretay pai ty Qustiona T.pdf
(0) L Utunled er- fon Rouacin- Feceta Fenerm teretay pai ty Qustiona T.pdf(0) L Utunled er- fon Rouacin- Feceta Fenerm teretay pai ty Qustiona T.pdf
(0) L Utunled er- fon Rouacin- Feceta Fenerm teretay pai ty Qustiona T.pdftheyellowgold
ย 
!!Please answer all questions !! 1-Identify the important system compo (1).pdf
!!Please answer all questions !! 1-Identify the important system compo (1).pdf!!Please answer all questions !! 1-Identify the important system compo (1).pdf
!!Please answer all questions !! 1-Identify the important system compo (1).pdftheyellowgold
ย 
Based on what you know about Mitochondria and ER protein import- Think.pdf
Based on what you know about Mitochondria and ER protein import- Think.pdfBased on what you know about Mitochondria and ER protein import- Think.pdf
Based on what you know about Mitochondria and ER protein import- Think.pdftheyellowgold
ย 
Based on its appearance and features- what kind of fault is this- (Not.pdf
Based on its appearance and features- what kind of fault is this- (Not.pdfBased on its appearance and features- what kind of fault is this- (Not.pdf
Based on its appearance and features- what kind of fault is this- (Not.pdftheyellowgold
ย 
Based on the Gilbert paper regarding human embryonic development- take.pdf
Based on the Gilbert paper regarding human embryonic development- take.pdfBased on the Gilbert paper regarding human embryonic development- take.pdf
Based on the Gilbert paper regarding human embryonic development- take.pdftheyellowgold
ย 
Based on the above FSM- answer the following questions- 1- Write out s.pdf
Based on the above FSM- answer the following questions- 1- Write out s.pdfBased on the above FSM- answer the following questions- 1- Write out s.pdf
Based on the above FSM- answer the following questions- 1- Write out s.pdftheyellowgold
ย 
Based on the ANOVA table given- is there enough evidence at the 0-01 l.pdf
Based on the ANOVA table given- is there enough evidence at the 0-01 l.pdfBased on the ANOVA table given- is there enough evidence at the 0-01 l.pdf
Based on the ANOVA table given- is there enough evidence at the 0-01 l.pdftheyellowgold
ย 
based on healthcare workplace conduct s 1 and 7- Lawful and Honest Co.pdf
based on healthcare workplace conduct  s 1 and 7- Lawful and Honest Co.pdfbased on healthcare workplace conduct  s 1 and 7- Lawful and Honest Co.pdf
based on healthcare workplace conduct s 1 and 7- Lawful and Honest Co.pdftheyellowgold
ย 
Barter Auto Repair had the following account balances after adjustment.pdf
Barter Auto Repair had the following account balances after adjustment.pdfBarter Auto Repair had the following account balances after adjustment.pdf
Barter Auto Repair had the following account balances after adjustment.pdftheyellowgold
ย 
Based on a poll- 61- of Internet users are more careful about personal.pdf
Based on a poll- 61- of Internet users are more careful about personal.pdfBased on a poll- 61- of Internet users are more careful about personal.pdf
Based on a poll- 61- of Internet users are more careful about personal.pdftheyellowgold
ย 
b- tackine dercingrumer organismis- 21- The process of killing or nias.pdf
b- tackine dercingrumer organismis- 21- The process of killing or nias.pdfb- tackine dercingrumer organismis- 21- The process of killing or nias.pdf
b- tackine dercingrumer organismis- 21- The process of killing or nias.pdftheyellowgold
ย 
Bank reconciliation and entries The cash account for Stone Systems at.pdf
Bank reconciliation and entries The cash account for Stone Systems at.pdfBank reconciliation and entries The cash account for Stone Systems at.pdf
Bank reconciliation and entries The cash account for Stone Systems at.pdftheyellowgold
ย 
Banele had a taxable estate of $17-4 million when they died this year-.pdf
Banele had a taxable estate of $17-4 million when they died this year-.pdfBanele had a taxable estate of $17-4 million when they died this year-.pdf
Banele had a taxable estate of $17-4 million when they died this year-.pdftheyellowgold
ย 
b- Write two additional sentences using the superficial-deep relations.pdf
b- Write two additional sentences using the superficial-deep relations.pdfb- Write two additional sentences using the superficial-deep relations.pdf
b- Write two additional sentences using the superficial-deep relations.pdftheyellowgold
ย 
B- Monetary System- The monetary base of Moneyland is $700 million- Th.pdf
B- Monetary System- The monetary base of Moneyland is $700 million- Th.pdfB- Monetary System- The monetary base of Moneyland is $700 million- Th.pdf
B- Monetary System- The monetary base of Moneyland is $700 million- Th.pdftheyellowgold
ย 
B- Metamorphic Environments Homework - Unanswered - Due Mar 1st- 11-59.pdf
B- Metamorphic Environments Homework - Unanswered - Due Mar 1st- 11-59.pdfB- Metamorphic Environments Homework - Unanswered - Due Mar 1st- 11-59.pdf
B- Metamorphic Environments Homework - Unanswered - Due Mar 1st- 11-59.pdftheyellowgold
ย 

More from theyellowgold (20)

(1 point) Suppose that X is normally distributed with mean 120 and sta.pdf
(1 point) Suppose that X is normally distributed with mean 120 and sta.pdf(1 point) Suppose that X is normally distributed with mean 120 and sta.pdf
(1 point) Suppose that X is normally distributed with mean 120 and sta.pdf
ย 
(1 point) Suppose we apply the Mix Columns operation to a -column- vec.pdf
(1 point) Suppose we apply the Mix Columns operation to a -column- vec.pdf(1 point) Suppose we apply the Mix Columns operation to a -column- vec.pdf
(1 point) Suppose we apply the Mix Columns operation to a -column- vec.pdf
ย 
#9 - Selective Repeat ARQ Protocol X attempts to send four frames (f0-.pdf
#9 - Selective Repeat ARQ Protocol X attempts to send four frames (f0-.pdf#9 - Selective Repeat ARQ Protocol X attempts to send four frames (f0-.pdf
#9 - Selective Repeat ARQ Protocol X attempts to send four frames (f0-.pdf
ย 
#2 A Treasury bond that matures in 10 years has a yield of 4-25-- A 10.pdf
#2 A Treasury bond that matures in 10 years has a yield of 4-25-- A 10.pdf#2 A Treasury bond that matures in 10 years has a yield of 4-25-- A 10.pdf
#2 A Treasury bond that matures in 10 years has a yield of 4-25-- A 10.pdf
ย 
(0) L Utunled er- fon Rouacin- Feceta Fenerm teretay pai ty Qustiona T.pdf
(0) L Utunled er- fon Rouacin- Feceta Fenerm teretay pai ty Qustiona T.pdf(0) L Utunled er- fon Rouacin- Feceta Fenerm teretay pai ty Qustiona T.pdf
(0) L Utunled er- fon Rouacin- Feceta Fenerm teretay pai ty Qustiona T.pdf
ย 
!!Please answer all questions !! 1-Identify the important system compo (1).pdf
!!Please answer all questions !! 1-Identify the important system compo (1).pdf!!Please answer all questions !! 1-Identify the important system compo (1).pdf
!!Please answer all questions !! 1-Identify the important system compo (1).pdf
ย 
Based on what you know about Mitochondria and ER protein import- Think.pdf
Based on what you know about Mitochondria and ER protein import- Think.pdfBased on what you know about Mitochondria and ER protein import- Think.pdf
Based on what you know about Mitochondria and ER protein import- Think.pdf
ย 
Based on its appearance and features- what kind of fault is this- (Not.pdf
Based on its appearance and features- what kind of fault is this- (Not.pdfBased on its appearance and features- what kind of fault is this- (Not.pdf
Based on its appearance and features- what kind of fault is this- (Not.pdf
ย 
Based on the Gilbert paper regarding human embryonic development- take.pdf
Based on the Gilbert paper regarding human embryonic development- take.pdfBased on the Gilbert paper regarding human embryonic development- take.pdf
Based on the Gilbert paper regarding human embryonic development- take.pdf
ย 
Based on the above FSM- answer the following questions- 1- Write out s.pdf
Based on the above FSM- answer the following questions- 1- Write out s.pdfBased on the above FSM- answer the following questions- 1- Write out s.pdf
Based on the above FSM- answer the following questions- 1- Write out s.pdf
ย 
Based on the ANOVA table given- is there enough evidence at the 0-01 l.pdf
Based on the ANOVA table given- is there enough evidence at the 0-01 l.pdfBased on the ANOVA table given- is there enough evidence at the 0-01 l.pdf
Based on the ANOVA table given- is there enough evidence at the 0-01 l.pdf
ย 
based on healthcare workplace conduct s 1 and 7- Lawful and Honest Co.pdf
based on healthcare workplace conduct  s 1 and 7- Lawful and Honest Co.pdfbased on healthcare workplace conduct  s 1 and 7- Lawful and Honest Co.pdf
based on healthcare workplace conduct s 1 and 7- Lawful and Honest Co.pdf
ย 
Barter Auto Repair had the following account balances after adjustment.pdf
Barter Auto Repair had the following account balances after adjustment.pdfBarter Auto Repair had the following account balances after adjustment.pdf
Barter Auto Repair had the following account balances after adjustment.pdf
ย 
Based on a poll- 61- of Internet users are more careful about personal.pdf
Based on a poll- 61- of Internet users are more careful about personal.pdfBased on a poll- 61- of Internet users are more careful about personal.pdf
Based on a poll- 61- of Internet users are more careful about personal.pdf
ย 
b- tackine dercingrumer organismis- 21- The process of killing or nias.pdf
b- tackine dercingrumer organismis- 21- The process of killing or nias.pdfb- tackine dercingrumer organismis- 21- The process of killing or nias.pdf
b- tackine dercingrumer organismis- 21- The process of killing or nias.pdf
ย 
Bank reconciliation and entries The cash account for Stone Systems at.pdf
Bank reconciliation and entries The cash account for Stone Systems at.pdfBank reconciliation and entries The cash account for Stone Systems at.pdf
Bank reconciliation and entries The cash account for Stone Systems at.pdf
ย 
Banele had a taxable estate of $17-4 million when they died this year-.pdf
Banele had a taxable estate of $17-4 million when they died this year-.pdfBanele had a taxable estate of $17-4 million when they died this year-.pdf
Banele had a taxable estate of $17-4 million when they died this year-.pdf
ย 
b- Write two additional sentences using the superficial-deep relations.pdf
b- Write two additional sentences using the superficial-deep relations.pdfb- Write two additional sentences using the superficial-deep relations.pdf
b- Write two additional sentences using the superficial-deep relations.pdf
ย 
B- Monetary System- The monetary base of Moneyland is $700 million- Th.pdf
B- Monetary System- The monetary base of Moneyland is $700 million- Th.pdfB- Monetary System- The monetary base of Moneyland is $700 million- Th.pdf
B- Monetary System- The monetary base of Moneyland is $700 million- Th.pdf
ย 
B- Metamorphic Environments Homework - Unanswered - Due Mar 1st- 11-59.pdf
B- Metamorphic Environments Homework - Unanswered - Due Mar 1st- 11-59.pdfB- Metamorphic Environments Homework - Unanswered - Due Mar 1st- 11-59.pdf
B- Metamorphic Environments Homework - Unanswered - Due Mar 1st- 11-59.pdf
ย 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
ย 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
ย 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
ย 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
ย 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
ย 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
ย 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
ย 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
ย 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
ย 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
ย 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
ย 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
ย 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
ย 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxDavid Douglas School District
ย 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
ย 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
ย 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
ย 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
ย 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
ย 

Recently uploaded (20)

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
ย 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
ย 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
ย 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
ย 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
ย 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
ย 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
ย 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
ย 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
ย 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
ย 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
ย 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
ย 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
ย 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
ย 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
ย 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
ย 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
ย 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
ย 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
ย 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
ย 

# -Gavin Lewis- # P9 - Employee Hash Table # The Hash Dictionary poi.pdf

  • 1. # [Gavin Lewis] # P9 - Employee Hash Table # The Hash Dictionary points to the first element of the Employee Linked List with its hash (0- 11) class HashDictionary: def __init__(self, hashLength): self.beginChain = [] self.endChain = [] for n in range(hashLength): self.beginChain.append(None) self.endChain.append(None) # Employee Linked List class Employee: def __init__(self, empID, empLastName, empFirstName, empPhone): self.empID = empID self.LastName = empLastName self.FirstName = empFirstName self.phone = empPhone self.nextEmployee = None # corrected variable name self.deleted = False # added deleted flag to mark deleted employees def __str__(self): # added string representation for Employee return "Employee ID: {}, Last Name: {}, First Name: {}, Phone: {}".format( self.empID, self.LastName, self.FirstName, self.phone) class EmployeeHashTable:
  • 2. def __init__(self, hashLength): self.hashDict = HashDictionary(hashLength) def insertEmployee(self, empID, empLastName, empFirstName, empPhone): position = empID % 12 currentNode = self.hashDict.beginChain[position] prevNode = None while currentNode is not None: prevNode = currentNode currentNode = currentNode.nextEmployee emp = Employee(empID, empLastName, empFirstName, empPhone) if prevNode is None: self.hashDict.beginChain[position] = emp else: prevNode.nextEmployee = emp print("Employee with ID {} added to database".format(emp.empID)) def searchEmployee(self, empID): position = empID % 12 currentNode = self.hashDict.beginChain[position] while currentNode is not None: if currentNode.empID == empID and not currentNode.deleted: # check for deleted flag print("Employee Found:n", currentNode) return currentNode currentNode = currentNode.nextEmployee
  • 3. print("Employee with ID {} not found".format(empID)) return None def deleteEmployee(self, empID): position = empID % 12 currentNode = self.hashDict.beginChain[position] while currentNode is not None: if currentNode.empID == empID and not currentNode.deleted: # check for deleted flag currentNode.deleted = True print("Employee with ID {} marked as deleted".format(empID)) return currentNode = currentNode.nextEmployee print("Employee with ID {} not found".format(empID)) def traverseChain(self, startEMP): print("Employee Chain:") print(" ", startEMP) node = startEMP.nextEmployee while node is not None: print(" ", node) node = node.nextEmployee # main program from random import randint import csv hashLength = 12
  • 4. empList = [] file = open('EmployeeDB.csv') csvreader = csv.reader(file) header = next(csvreader) for employee in csvreader: empList.append(employee) HD = HashDictionary(hashLength) for empRecord in empList: empID = int(empRecord[0]) empLastName = empRecord[1] empFirstName = empRecord[2] empPhone = empRecord[3] EMP = Employee(empID, empLastName, empFirstName, empPhone) HD.insertEmployee(EMP) empIDin = input("Enter Employee ID (001-999, 0 to Exit): ") empID = int(empIDin) while (empID > 0 and empID < 1000): oper = input("Enter Operation Type (S)earch, (I)nsert, (D)elete: ") if (oper == "S"): E = HD.searchEmployee(empID) if (E != None): print(E.empID, E.FirstName, E.LastName, E.phone) else:
  • 5. print(empID, " Doesn't Exist") elif (oper == "I"): E = HD.searchEmployee(empID) if (E != None): print (empID, " Already Exists.", E.LastName, " Cannot Have Duplicates") else: fName = input("Enter Employee First Name: ") lName = input("Enter Employee Last Name: ") phoneNum = input("Enter Employee Phone Number: ") EMP = Employee(empID, lName, fName, phoneNum) HD.insertEmployee(EMP) print (EMP.empID, EMP.LastName, " Record Inserted") elif (oper == "D"): E = HD.searchEmployee(empID) if (E != None): HD.deleteEmployee(empID, E) print (E.empID, E.LastName, " Deleted") else: print(empID, " Not Found. Cannot Delete") empIDin = input("Enter Employee ID (001-999, 0 to Exit): ") empID = int(empIDin) for n in range(hashLength): print (n)
  • 6. if (HD.beginChain[n] != None): traverseChain(HD.beginChain[n])