changing the getTotalDistanxw fuction based on linked list