-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHashing Records.py
More file actions
48 lines (39 loc) · 1.25 KB
/
Hashing Records.py
File metadata and controls
48 lines (39 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class Customer:
CustomerID = 0
CName = ""
Contact = ""
isActive = False
MaxIndex = 9
CustomerArray = [Customer for x in range(MaxIndex+1)] #RECORD
def Hash(Key):
global MaxIndex
global CustomerArray
Address = Key % (MaxIndex+1)
return Address
def Insert(NewRecord):
global CustomerArray
Index = Hash(NewRecord.CustomerID)
while CustomerArray[Index].CustomerID!=0:
Index +=1
if Index>MaxIndex:
Index = 0
CustomerArray.insert(Index,NewRecord)
def Search(ThisID):
Index = Hash(ThisID)
while CustomerArray[Index].CustomerID != ThisID and CustomerArray[Index].CustomerID !=0:
Index+=1
if Index >MaxIndex: Index = 0
if CustomerArray[Index].CustomerID!=0:
return CustomerArray[Index]
else:
return -1
ThisID = int (input ("Enter customer ID [0 to exit]: "))
while ThisID != 0:
newRecord = Customer()
newRecord.CustomerID = ThisID
newRecord.CName = input("Enter Customer name:")
Insert(newRecord)
ThisID = int (input ("Enter customer ID [0 to exit]: "))
#print(Search(int(input("Enter ID: "))))
for x in range(MaxIndex):
print(CustomerArray[x].CustomerID,CustomerArray[x].CName)