English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

it creates one sorted list.each file should contain <=15no.s.1st create a programme that randomly chooses a size(<=15no.s.)for the list 1 then randomly generates a list of no.sand store them in file 1.repeat this procedure to select the other two lists of no.s and store them in file 1.repeat this procedure to select the other two lists(list2&list 3) & store them in corresponding files(file2&file3) for sorting & merging them into one.
file1(list1)32 12 5 990 1
file2(list2)2000 3
file3(list3)30 6
output in separate file:1 3 5 6 12 30 32 990 2000

2007-03-02 01:57:18 · 2 answers · asked by ANURADHA B 1 in Computers & Internet Programming & Design

2 answers

Sounds like a homework problem... Shouldn't you do that yourself?

2007-03-02 19:21:11 · answer #1 · answered by BigRez 6 · 0 0

before answering, you need in the future to put a space at the beginning of lines to start a new linie so you don't get stuff like <=15no.s 1st.
I assume you can do the storage.
Making the sorted merge is easiest with an insert sort.
You may wish to open each of the 3 files and read how many numbers there are total to dimension the array to hold them (better for larger arrays later) or you can just set the storage array to the largest possible (45 = 3 * 15 max.)
Initialize the array to 0 and init a pointer to the beginning.
Open the first file, read a number, insert it at the pointer and call the sort (below). Repeat with the remaining numbers. Repeat with the remaining files. Print the result.
The sort simply consists of setting a compare pointer to the insert pointer minus 1, checking to see if the compare pointer has reached zero, and if not comparing the number at the compare point with the next below and if the one at the compare point is smaller, swapping them. In your example, when the last number of the 3rd file (6) is read in the insert pointer is at 8 with numbers at positions 0 to 7. The 6 is put at 8 and the insert pointer increased. The number at position 8 (6) is compared to the one at 7 (2000) and because 6 is lower, the two are swapped. This is repeated until the compare pointer is at 3 (6) and the next below is 5, when it stops.

2007-03-03 03:28:18 · answer #2 · answered by Mike1942f 7 · 0 0

fedest.com, questions and answers