Yes, there are springs design to work well in both compression and tension, though they generally
- cost a fair amount, and
- will extend farther than they will compress.
But it's hard to set up the one-sided horizontal arrangement shown in books because of the springs tendency to buckle as well as the difficulty in removing friction from the spring's interaction with the surface. The two sided version is easy to realize on the bench, as is the vertical one-sided arrangement (you just sum the spring constants), as is the vertical one-sided arrangement. Of course it take a little more math to show that the vertical problem is completely equivalent to the horizontal one.