Q1:99999

1. Shellsorting a linked list Implement Shellsort for a linked list, based on a variant of bubble sort. The rather severe constraints imposed by the singly-linked list organization presents special problems for implementing Shellsort. Your task is to overcome these constraints and develop a simple, elegant implementation that does not sacrifice efficiency or waste space. Step 1. First, implement a routine to build a list: read integers from standard input, and build a list node for each item consisting of an integer key and a link to the node for the next item. Also, write a routine to print out the contents of the linked list. Step 2. Next, implement bubble sort: it should take as input a link to the beginning of a list, and should rearrange the nodes of the list so that they are in sorted order. This is not the same as rearranging keys within nodes: that is to be avoided because, in real applications, other information might be associated with the keys, or other data structures might have pointers to the nodes. You may use dummy nodes or circular lists as you see fit, but do not use doubly-linked lists. That is, you should use only one link per node, with a constant extra number of links for bookkeeping. Step 3. Next, implement a bubble h-sort. You will need to discover an efficient way to do this, even for large h. Make sure that one pass of your bubble h-sort uses at most a constant amount of auxiliary space and runs in time linear in the input size N. Note that h does not count as a constant - this is too much. However, in general, your bubble h-sort routine will still need more than a constant number of passes to produce a file that is h-sorted. You should think about how you are going to solve this problem before writing the code. Step 4. Finally, write a Shellsort variant that uses your bubble h-sort. Use Knuth's increment sequence (1, 4, 13, 40, ..., (3^𝑛−1 )/2 ).

上面是第一道题的代码实现步骤,请认真阅读之后给我一个新的正确代码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值