0

Mergesort can be done in-place for list;unlike an array.
However,I have not found a reference yet which explains how this is achieved.
Any pointer is appreciated.

IUnknown
  • 9,301
  • 15
  • 50
  • 76

1 Answers1

0

It actually is possible, though not straightforward, to implement an in-place merge sort for arrays. With linked lists the problem becomes quite simple. Each node in a linked list just has a value and a pointer to the next node. It is quite simple to break a linked list in half. Just traverse to the middle node, take its successor as the head of your second list and then set successor to null.

The merge step works just like you would expect. Don't make any new nodes, just relink the nodes from your two lists.

Wcrousse
  • 203
  • 2
  • 10