2017-07-09 12:18:22 +00:00
|
|
|
extends: post.liquid
|
2012-05-07 20:31:24 +00:00
|
|
|
title: swap in double-linked lists
|
2017-07-09 12:18:22 +00:00
|
|
|
date: 07 May 2012 22:22:00 +0200
|
|
|
|
path: /:year/:month/:day/swap-in-double-linked-lists
|
2017-12-19 21:26:32 +00:00
|
|
|
route: blog
|
2012-05-07 20:31:24 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
Yesterday I had to implement [Selection Sort](http://en.wikipedia.org/wiki/Selection_sort)
|
|
|
|
for double-linked lists and I had some trouble finding the correct solution
|
|
|
|
when it comes to swapping two elements.
|
|
|
|
|
|
|
|
But I finally figured out how to correctly swap the pointers and I'll drop the
|
|
|
|
code here so others can use it (or even tell me about hidden bugs)
|
|
|
|
|
|
|
|
I implemented it in Java, so see here:
|
|
|
|
|
|
|
|
<script src="https://gist.github.com/2630183.js"> </script>
|