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 ).
上面是第一道题的代码实现步骤,请认真阅读之后给我一个新的正确代码。