""The Design of Hash Table"
The school gives free gifts to students throughout the day. Gifts are distributed in the cafeteria. The rules are: before each student enters the cafeteria, a card will be issued with the window number and gift type printed on the card. When the canteen is in the peak dining period, only different types of gifts are stored in a certain window. When students come to collect gifts, the staff of that window finds the corresponding gifts to give to the students; when the dining crowd retreats, store each gift in a different window , The student will go to the corresponding window to receive the gift according to the serial number on the card. If there is no gift on the card in the window, go to the next window to receive the gift, and so on. Please use the hash table to realize the gift collection activity.
The procedures for simulating the gift-receiving activities during the peak dining period and when the dining crowd retreats are respectively compiled, as follows.
(1) Suppose there are 5 kinds of gifts, the numbers of each kind of gift are 1, 2, 3, 7, 9 respectively, and each kind of gift shall be filled up after receiving it.
(2) When there are many people at the table, the number of windows for receiving gifts can be set to 4. At this time, the hash function is constructed by the method of dividing and leaving the remainder, the zipper method is used to resolve the conflict, and the lookup of the hash table is used to simulate receiving a gift.
(3) When the flow of dining people recedes, the number of windows for receiving gifts increases to 6. At this time, the method of dividing and leaving the remainder is used to construct the hash function, the linear detection method is used to resolve the conflict, and the search function of the hash table is used to simulate receiving gifts."