algorithm - Implement a queue which keeps non-decreasing -
As everyone knows, a standard queue supports two basic functions: You just have to change the code Use a recursive function and every time Check whether your new element is larger than the element in the middle of the list, if not, try to insert the new element to the left side of the queue and try to insert on the right side of the queue until you find the right place for the elementDo not find. Dilute algorithm for inserting insert and
popout . And
insert is on the tail of the queue, while
popout is at the top of the queue. Here, I do not know if I can keep this queue in sequentially, as if on the basis of this lack, based on these two operations, or maybe with some additional help functions to achieve that goal?
insert in the queue, it can be obtained with the following algorithms:
o (lg (n)) .
popout you just done what you can do now, the last element pop out.
Comments
Post a Comment