For example, user A spent two yuan to buy 100 bottles of water today. The market price is now 2 fast money, and then submit A ticket: when the market price rises to 2.5 yuan, he will sell 100 bottles. A is just waiting for A person to buy B User: now the market is assumed to be 3 yuan; then the order of 2.5 yuan to buy 50 bottles. Question: How does PHP use queue to enable automatic purchase of B users?
User A spent two yuan today to buy 100 bottles of water; the market is now two quick money; then the ticket: when the market rose to 2.5 yuan to sell 100 bottles. A. Just wait for someone to buy it.
User B: the current market price is assumed to be 3 RMB, and then 50 bottles will be purchased for 2.5 RMB for a ticket.
Problem
PHP uses queue to realize that user B automatically buys 50 bottles of user. B. The transaction is completed. The transaction of A has not been sold out yet, and the ticket is still pending; how to implement this transaction for N users.
Description
Reply content: for example
User A spent two yuan today to buy 100 bottles of water; the market is now two quick money; then the ticket: when the market rose to 2.5 yuan to sell 100 bottles. A. Just wait for someone to buy it.
User B: the current market price is assumed to be 3 RMB, and then 50 bottles will be purchased for 2.5 RMB for a ticket.
Problem
PHP uses queue to realize that user B automatically buys 50 bottles of user. B. The transaction is completed. The transaction of A has not been sold out yet, and the ticket is still pending; how to implement this transaction for N users.
Description
This problem has nothing to do with the language.
Two queues are required. one is used to store "buy" and the other is used to store "sell". The queues are sorted by price and the same price is sorted by time.
Then, the program constantly compares the highest and lowest selling prices. if there is an overlap between the two, the transaction price is calculated based on the selling price.