Results 1 to 2 of 2

Thread: merge sort and linked list

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Posts
    4

    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?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
  •  



Click Here to Expand Forum to Full Width