Puzzling Problem: Going back to the previous directory

Hi,

I am trying to figure out if there is a way to make linux take me back to the previous directory I was working in. For instance, I am in

/home/username/directory1

Then if I cd into /home/username/directory1/temp1/temp2/temp3

I would like to immediately go back to the previous directory that I visited i.e. directory1 and when I type the same command it should take me back to temp3 so basically switching between directories should be done instantly. Is there any way I could do this in command line?

How about setting alias?

alias dir1="cd /home/username/directory1"
alias temp3="cd /home/username/directory1/temp1/temp2/temp3"

then just enter dir1 to goto directory1, temp3 to temp3 folder.

cd -

toggles from one dir to the last visited