NodeQs Partition(NodeQs l, NodeQs h)
        {
            int x = h.data;

            NodeQs i = l.prev;
            int    temp;

            for (NodeQs j = l; j != h; j = j.next)
            {
                if (j.data <= x)
                {
                    i      = i == null ? l : i.next;
                    temp   = i.data;
                    i.data = j.data;
                    j.data = temp;
                }
            }

            i      = i == null ? l : i.next;
            temp   = i.data;
            i.data = h.data;
            h.data = temp;

            return(i);
        }
 void QuickSortSub(NodeQs l, NodeQs h)
 {
     if (h != null && l != h && l != h.next)
     {
         NodeQs temp = Partition(l, h);
         QuickSortSub(l, temp.prev);
         QuickSortSub(temp.next, h);
     }
 }
        NodeQs LastNode(NodeQs node)
        {
            while (node.next != null)
            {
                node = node.next;
            }

            return(node);
        }
        public void Push(int data)
        {
            NodeQs newNode = new NodeQs(data);

            if (head == null)
            {
                head = newNode;
                return;
            }

            newNode.next = head;
            head.prev    = newNode;
            newNode.prev = null;
            head         = newNode;
        }
        public void Sort(NodeQs node)
        {
            NodeQs head = LastNode(node);

            QuickSortSub(node, head);
        }
 public NodeQs(int d)
 {
     this.data = d;
     next      = null;
     prev      = null;
 }