algorithm - Implement a queue which keeps non-decreasing -


As everyone knows, a standard queue supports two basic functions: 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?

You just have to change the code a bit. Every time you want to find a new element in the queue insert in the queue, it can be obtained with the following algorithms:

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 o (lg (n)) .

popout you just done what you can do now, the last element pop out.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -