Let me discuss this as it used to work in the old days before everything became electronic. The principle is the same, but it's more complicated today.
Say you want to buy some stock in XYZ Company. You place an order with your stock broker. In the old days the broker would go to the floor of a stock exchange and go to the area where they were trading XYZ. Then he would shout that he wanted to buy (say) 100 shares of XYZ at $50 per share. Someone willing to sell would say $55. They'd dicker a bit and settle on a price and then make the sale. If there were more people who wanted to buy than wanted to sell, the seller could say, "No, I'm not taking $50, this guy over here is offering $52." Or if there were more sellers than buyers the buyer could say "No, I"m not going to give you $55, this guy over here will sell for $53." At some point the price would get high enough that some number of buyers would say forget it, I'm not going to buy at that price. Or it would go low enough that some number of sellers would say, Never mind, I'll just hang on to it, maybe see if I can get a better deal next week. And so the price would settle on a number where the number of shares offered for sale at that price was equal to the number that people wanted to buy at that price. As all the buyers and sellers were in one room, the market was very "efficient" in an economist's sense: everyone had all the information about what was being offered and at what price.
For this to work they had to keep the number of buyers and sellers manageable. There might be 10,000 people who want to buy General Motors stock today, but it would be impractical to get them all in the same room. So they would sell a limited number of "seats" on the stock exchange to brokers, who would then represent their clients.
This means that if you're a typical small investor, you don't directly participate in the negotiation. You tell your broker you want to buy XYZ Company, and he goes to the exchange and gets the best deal for you that he can get. Ultimately, your buy and sell decisions, when aggregated with all the millions of other small investors in the world, determine the price. But you as one person have very little influence.
It's just like, if you buy a toaster at Wal-Mart and the price tag says $10, that's the price and you can take it or leave it. If you go to the store manager and say "I'll give you $9 for this toaster, that's my final offer", he's just going to look at you funny. But if a thousand customers look at that toaster and say, "I'm not going to pay $10 for that. Maybe I'd pay $9", ultimately Wal-Mart will drop the price to $9. Or if they find that they put toasters on the shelf for $10 and they sell out in five minutes, they'll try upping the price and see what happens.
What if someone wants to buy but no one wants to sell? Or vice versa? The stock markets have "specialists" who pledge that they will buy or sell some stock as the buyer/seller of last resort.
When a stock is bought and sold many times in one day, the market will quickly settle on a "going rate". There are some stocks, especially smaller companies, that may go many days without a trade. These get ... fuzzier. Like just recently I wanted to buy a certain stock, I saw the last offer was for like $90 a share, so without doing any research (idiot ...) I said ok, I'll buy it at $90 a share. My broker called me and told me the going price for that stock was more like $20 a share, but it was infrequently traded so $90 was the last offer. He asked if I really wanted to buy at that price and I said no thanks, thanks for letting me know.
So regarding your hypothetical: If you were talking about a frequently traded stock, that just would never happen, so the question is meaningless. For an infrequently traded stock, a good broker would say, "Hmm, yesterday the only sale was for $200, but three days ago there was a sale for $180." And he'd bid $180 and see if there were any sellers at that price. If not, a good broker would ask you what you want to do. Web trading sites that I've used require you to set a maximum buy or minimum sell price. So like if I see that the going rate is $180 despite that unusual high sale yesterday, I might say that my maximum bid is $182, and if no one will sell at that price within 24 hours (or whatever period), the buy is cancelled.