Can I reverse a queue without using stack?
问题 I have a queue with some numbers for example 5,6,7,8 is in queue, 5 is q->front and 8 is q->rear.. Can I reverse them in queue but without using stacks? 回答1: Of course! But it won't be as efficient. Using a stack: O(N) time. O(1) memory. Using an associative array: O(N) time. O(1) memory. Using a fixed-size array: O(N) time. O(N) memory. Using an extendable array: O(N) time. O(N) memory. Using a queue: O(N^2) time. O(1) memory. Using an associative array will use more time than using a stack,