When winging it you need to have Plan A, B and C. We just went to Yellowstone, hoping for Mammoth CG(only 2 cgs open, on N and 1 S) if not we were aware of 2 NFS service locations 15 miles down the road.
It also sounds like you were traveling late into the day(Visitor Center closed). We mostly settle in by 4 at the latest.
You also need to be aware of all the opportunities for an overnight. Cracker Barrel is one but there are so many others.
The other trick is not to travel on a weekend. Where we are on Friday(early) is where we stay until Sunday.
There are numerous campgrounds that don't appear in any books, you find them mainly on the backroads, not on interstates.
Harvest Hosts is a good resource if you belong. I have never been turned away from them. Also, Elks(you need to join) has numerous lodges across the US.
You will learn...........