implemented reverse order of words algorithm