finished question4.7...without using external storage and parent pointer