title: Re-ordering a Linked List in Python
body: <p>I realize this sort of data structure is better done with built in list type, but I'm trying to understand this more for academic reasons. Given that I have a linked list like this:</p>
  
  <p>a -> b -> c -> d -> e -> f</p>
  
  <p>I would like to change the references to</p>
  
  <p>b -> a -> d -> c -> f -> e</p>
  
  <p>In other words every pair gets switched. I am using these two classes to create a linked list.</p>
  
  <pre><code>class Node:
      def __init__(self):
          self.cargo = None 
          self.next = None 
  
  class LinkedList:
      def __init__(self):
          self.cur_node = None
  
      def add_node(self, cargo):
          new_node = Node() 
          new_node.cargo = cargo
          new_node.next = self.cur_node 
          self.cur_node = new_node
  
      def print_list(self):
          node = self.cur_node
          while node:
              print node.cargo
              node = node.next
  
      def reorder(self):
          # missing code here!
  
  
  ll = LinkedList()
  ll.add_node("a")
  ll.add_node("b")
  ll.add_node("c")
  ll.add_node("d")
  ll.add_node("e")
  ll.add_node("f")
  ll.reorder()
  ll.print_list()
  </code></pre>
  
  <p>Any ideas?</p>