Question: Please give an easy code example for this problem. I do have my code I'm just not understanding the links part. Again please give a

Please give an easy code example for this problem. I do have my code I'm just not understanding the links part. Again please give a code example and explain it.

1. Write a program to read an input sequence and then produce an array of links giving the values in ascending order. The

first line of the input file is the length of the sequence (n) and each of the remaining n lines is a non-negative integer. The

first line of the output indicates the subscript of the smallest input value. Each of the remaining output lines is a triple

consisting of a subscript along with the corresponding input sequence and link values.

Getting Started:

1. Your program should read the input files by using Unix shell redirection (e.g. a.out

stdin (C).

2. The link values are not initialized before the recursive mergesort begins. Each link will be initialized to -1 when its

sequence value is placed in a single-element list (at the bottom of the recursions tree).

3. The input sequence array and the link array may be global. Under this assumption, the following prototype may be used:

int mergeSort(int start,int count) where start is the first subscript for a subarray of count elements. The returned int is the subscript of the first

element in the resulting sorted sublist. The last element in the sublist will have a link value of -1.

4. The critical part of the code is a merge of two subarrays that previously had their link values set for ordered sublists. The

merge will revise the link values to give a single ordered list.

5. If an input value appears more than once, those elements should be ordered by subscripts in the final list, i.e. your sort

code will be stable.

6. Consider the following input file:

8

3

5

6

7

0

4

1

2

The output will be:

First element is at subscript 4

0 3 5

1 5 2

2 6 3

3 7 -1

4 0 6

5 4 1

6 1 7

7 2 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!