|
-
Nov 1st, 2001, 06:16 PM
#1
Thread Starter
New Member
merge sort and linked list
i am trying to creat a program in C++ that will read in 3 sorted files(with 15 interger values each), use the merge sort with linked lists, and output a new file. how would i do this?
-
Nov 2nd, 2001, 02:24 AM
#2
transcendental analytic
merge sort for single linked list:
merge sort merges sorted partitions from smallest of 2 to whole range (incremention is power of two (2,4,8...)
You can start by running trough the list and comparing each second partition with the one following it and swap them as needed. To merge larger partitions you have these special cases:
first.last > second.first : just link em up
second.first > first.last : link em up in inverse order
otherways run trough first or last until you hit the other, linking up each item, then start linking up from both sides until one of them ends, and lastly link the rest of the remaining partition.
when you have reached last loop, where only big two partitions are left, take into account that the second will be of size: total-firstpartitionsize
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|