Link to home
Start Free TrialLog in
Avatar of jwirth779
jwirth779

asked on

External Sorting

I need a simple (im sure its simple for you guys) algorithm that can sort a large textfile.

          i need my program to first sort and then merge (nothing new!!) . the sorting stage would split my large textfile into several smaller  sorted textfiles and and the merging stage would merge all these textfiles together to make the final sorted textfile. i have tried it myself but i cannot figure out the algorithm ( i always get stuck at some point and realise i cannot continue).
         i dont want to have to use pointers...maybe there is some recursive method ??(not sure). i have looked at swag but there doesnt seem to be anything close enough to what i need.

Any help is more than appreciated !!! :)

Thanks a real lot!



Avatar of Jase-Coder
Jase-Coder

how do you want them sorted, I mean you could sort by alphabetical, length of line, numerical?
Avatar of jwirth779

ASKER

numerical....ascending order preferably!!!
Avatar of Mike McCracken
Homework per chance?

mlmcc
no... why do you ask? im gonna increase the points...
i have a program which will sort 20000 numbers (but very fast) in ascending order!! Would you like to apadpt it (my sorting program) for you to make the numbers as an input from your textfile?
yes that would be really good of you. but the thing is that i must use the sort and merge procedure that i described before (it is a technique so ill be able to sort even if i dont have enough memory - but im sure you know that already) Does your program use a sort and merge algorithm?

Thanks again for all you help!!! :)
no it does not use merge. Do you want it without the merge algorithm (it is still very effecient - it picks up 20000 random numbers and then sorts them in an average speed of less that 4.5 seconds, i think that would be effecient enough!)
the thing is that i really need a sort and merge algorithm so ill be able to sort a textfile no matter what the size of the textfile is....
this is an exmple of my textfile :
test      01      26      test
test      02      15      test
test      03      66      test
test      04      37      test
test      05      61      test
test      06      33      test
test      07      95      test
test      08      99      test
test      09      31      test
test      10      82      test
.               .               .               .
.               .               .               .
.               .               .               .  
test           500           34            test


there are 500 hundred lines.... and the second colomn of numbers are between 1-100 (colomn to be sorted!!).
preferably this textfile is split up in 10 smaller sorted files and then merged to form one large sorted file!!

any idea????

thanks guys!!
i made a program which splits an unsorted textfile in 10 other textfiles. Sort the textfile and then create a new sorted textile!

SAMPLE INPUT IN UNSORTED TEXTFILE:

1  12
2  14
3  19
4  89
5  27
6  20
7  73
8  10
9  46
10 28
11 32
12 44
13 59
14 69
15 77
16 80
17 93
18 100
19 26
20 38

SAMPLE OUTPUT IN SORTED TEXTFILE

10
12
14
19
20
26
27
28
32
38
44
46
59
69
73
77
80
89
93
100

This is what you wanted or something similar!!! Hope i've of help. I you want it just tell me! :)
yeah that sounds great!! do you think you could pass it on to me???
it is a little bit long! do you have an email so i can send it to? Otherwise i write it for you
ASKER CERTIFIED SOLUTION
Avatar of alandemartino
alandemartino

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it looks real good...thx alot....im gonna go over it and then give you the points.... cheers mate.
no problem man!!!!!
Did it work!!
yeah it works ok

im just having abit of a problem adapting it to for example 500 records... its more than good enough though...thanks alot!!!

i might have a couple of problems still.... if you want ill give you the points anyway!!
I appreciate it very much. :)
im having a problem to modify it to 1000 records for example....how come?
ok sorted!! cheers...


all yours!
Thank you very much, and by the way if you need anymore help,  as long as i know i will help you