// FIXME public void Sort() { bool swap = true; ListNode lastSwap = tail; // empty or a single entry, just return if (head == null || head.Next == null) { return; } while (swap) { swap = false; ListNode loopEnd = lastSwap; for (ListNode curNode = head; curNode != loopEnd; curNode = curNode.Next) { ListNode nextNode = curNode.Next; // if we need to move things, swap the data if (curNode.ToString().CompareTo(nextNode.ToString()) > 0) { Object tmp = nextNode.getData(); nextNode.setData(curNode.getData()); curNode.setData(tmp); swap = true; lastSwap = nextNode; } } } }
public void AddFirst(object o) { ListNode node = new ListNode(); node.setData(o); node.Next = head; head = node; if (tail == null) { tail = node; } }
public void AddLast(object o) { ListNode node = new ListNode(); node.setData(o); if (tail != null) { tail.Next = node; } else // empty list, so set head as well { head = node; } tail = node; }