Share your repls and programming experiences

← Back to all posts
01数据库课程设计
h
xxynly (0)

《哈希表的设计》
校全天免费赠送学生礼物。礼物的发放在食堂进行,其规则为:每名学生进入食堂之前发一张卡片,卡片上印有领取礼物的窗口号和礼物种类。当食堂处于就餐高峰期时,仅将不同种类的礼物存放在某一个窗口,当学生来领取礼物时该窗口员工找到相应礼物赠送给学生;当就餐人流退去时,将每种礼物存放在不同窗口,学生根据卡片上的序号到相应窗口领取礼物,若该窗口没有卡片上的礼物,则到下一个窗口领取,依次类推。请借助于哈希表来实现领取礼物的活动。
分别编写模拟就餐高峰期和就餐人流退去时领取礼物活动的程序,具体如下。
(1)假设有5种礼物,每种礼物的编号分别为1、2、3、7、9,每种礼物领完后补齐。
(2)当就餐人数较多时,可将领取礼物的窗口数设为4。此时用除留余数法构建哈希函数,拉链法解决冲突,利用哈希表的查找模拟领取礼物.
(3)当就餐人流退去时,领取礼物的窗口数增加为6。此时利用除留余数法构建哈希函数,线性探测法解决冲突,利用哈希表的查找功能模拟领取礼物。

Comments
hotnewtop
maxina (43)

""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."