Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Merge sort
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Bottom-up implementation using lists=== [[Pseudocode]] for bottom-up merge sort algorithm which uses a small fixed size array of references to nodes, where array[i] is either a reference to a list of size 2<sup>''i''</sup> or ''[[Null pointer|nil]]''. ''node'' is a reference or pointer to a node. The merge() function would be similar to the one shown in the top-down merge lists example, it merges two already sorted lists, and handles empty lists. In this case, merge() would use ''node'' for its input parameters and return value. '''function''' merge_sort(''node'' head) '''is''' // return if empty list '''if''' head = nil '''then''' '''return''' nil '''var''' ''node'' array[32]; initially all nil '''var''' ''node'' result '''var''' ''node'' next '''var''' ''int'' i result := head // merge nodes into array '''while''' result β nil '''do''' next := result.next; result.next := nil '''for''' (i = 0; (i < 32) && (array[i] β nil); i += 1) '''do''' result := merge(array[i], result) array[i] := nil // do not go past end of array '''if''' i = 32 '''then''' i -= 1 array[i] := result result := next // merge array into single list result := nil '''for''' (i = 0; i < 32; i += 1) '''do''' result := merge(array[i], result) '''return''' result
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Merge sort
(section)
Add topic