top sort with deque