ESc101 Laboratory Assignment Tuesday of Week of 25/10/04 Write a program to sort "N" (a power of 2) integers stored in a file, say FileA.dat using Iterative Merge Sort. The sorting algorithm is as follows: - Consider original list as N sublists of size 1. - Scan through list performing 1-by-1 mergers to produce N/2 sorted sub-lists of 2 elements - Scan through list performing 2-by-2 mergers to produce N/4 sorted sub-lists of 4 elements and so on. In each step merge first and second sub-list, third and fourth sub-list so on. For example, suppose the list to be sorted is : 23 13 14 26 19 11 16 17 Then, get (8/2=)4 sorted sublists as: 13 23 14 26 11 19 16 17 Now, (8/4=)2 sorted sublists as: 13 14 23 26 11 16 17 19 Now, (8/8=)1 sorted list as: 11 13 14 16 17 19 23 26 How to merge two sorted sublists: Keep an index-pointer (index varible) pointing at the first element of each sublist. Compare the two elements and output the smaller. Then increment the pointer of the sub-list from where we output. For example to merge 13 14 23 26 and 11 16 17 19 and output = empty | | next step 13 14 23 26 and 11 16 17 19 and output= 11 | | next step 13 14 23 26 and 11 16 17 19 and otuptu= 11 13 | | so on... Use of arrays is not allowed. Use a second file, FileB.dat for The sorting algorithm is as follows: the process as described below. In the first iteration, read from FileA.dat and write into FileB.dat. In the second iteration read from FileB.dat and write into FileA.dat. In this way alternate till sorting is complete. If final result ends up in FileB.dat, then copy it in FileA.dat. Open the file FileA.dat twice because you need to maintain two indices into the file. They should point to the beginning of the two sublists(of size say s) currently being considered for merging. The merged list is written to the second File. After one iteration, the partly sorted file is now in FileB.dat. Now adjust the two indices in FileB.dat properly and repeat the above process. Note that the above method should be other than "main". Then in the "main" method call the sort method. You should use text-file so that you can create the data-file directly. Q: Can you modify your program to deal with any N? If you have time, then try it.