Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6585fbd

Browse files
Three Hundred - Twenty Commit: Implement search() function
1 parent 1937ace commit 6585fbd

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

‎Section_11(Hash-Table)/(2)_hash-table-linear-probing.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ def lprobe(self, element):
2828
j = j + 1
2929
return (i + j) % self.hashtable_size
3030

31-
# Function to insert elements into the Hash Table
32-
31+
# Function to insert elements into the Hash Table
3332
def insert(self, element):
3433
i = self.hashcode(element)
3534
if self.hashtable[i] == 0:
3635
self.hashtable[i] = element
3736
else:
3837
i = self.lprobe(element)
3938
self.hashtable[i] = element
39+
40+
# Function to search for an element in the Hash Table
41+
def search(self, key):
42+
i = self.hashcode(key)
43+
j = 0
44+
while self.hashtable[(i + j) % self.hashtable_size] != key:
45+
if self.hashtable[(i + j) % self.hashtable_size] == 0:
46+
return False
47+
j = j + 1
48+
return True

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /