We stayed in the north pines campground in Yosemite Valley. I was able to get a site for 3 nights about 30 days in advance, then after that by being at the registration office by 6:30 am (it opens at 8am) I was able to extend my stay day by day. For us it was much more convenient to stay in the valley.
The last time we went to Yellowstone we actually stayed just outside of the western border of the park in a little town called West Yellowstone, next time we will probably stay in the park instead. We also really enjoyed the Black Hillls, Custer State Park and Glacier NP.