Write a program that reads two positive integers D and i (in this order) from its input and adds the rest of the integers (all non-negative) in the input to a hash table of size D. Finally the program should output the content of the table. Use closed hashing with linear probing where the parameter is i and h(x)=x. The content of the table should be printed in the following format: -1 7 8 ..... where the output contains exactly D lines and an empty slot is printed as -1.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

"please turn this python code to c++"

class hashTable:
def _init_(self):
self.size = int(input('Enter the size of hash table:'))
#initializwe the table with 0
self.table = list(None for i in range(self.size))
self.elementCount = 0

# function to get the position for element
def hashFunction(self,key):
return key%self.size

#function to check if hash table is full or not
def isFull(self):
if self.elementCount == self.size:
return True
else:
return False

#function to insert data into hash table
def insert(self,data):
#check if table is full
if self.isFull():
print("hash table is full")
return False


position = self.hashFunction(data)

#checking if positiohn is empty
if self.table[position] == None:
self.table[position] = data
self.elementCount+=1

#if collision occur linear probing is done
else:
while self.table[position] != None:
position+=1
if position >= self.size:
position = 0

self.table[position] = data

#function to display the hash table
def display(self):
for i in range( self.size):
print(self.table[i]+"\n")


ht = hashTable()
i = int(input("Enter interger to be inserted into hash table"))
ht.insert(i)
ht.display()

 

 

 

 

 

 

Write a program that reads two positive integers D and i (in this order) from its input and adds the rest of
the integers (all non-negative) in the input to a hash table of size D. Finally the program should output the
content of the table.
Use closed hashing with linear probing where the parameter is i and h(x)=x.
The content of the table should be printed in the following format:
-1
7
8
.....
where the output contains exactly D lines and an empty slot is printed as -1.
Transcribed Image Text:Write a program that reads two positive integers D and i (in this order) from its input and adds the rest of the integers (all non-negative) in the input to a hash table of size D. Finally the program should output the content of the table. Use closed hashing with linear probing where the parameter is i and h(x)=x. The content of the table should be printed in the following format: -1 7 8 ..... where the output contains exactly D lines and an empty slot is printed as -1.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY