employer cover photo
employer logo
employer logo

Susquehanna International Group

Employeur impliqué

Question d’entretien chez Susquehanna International Group

How to reverse the link list?

Réponse à la question d'entretien

Utilisateur anonyme

25 août 2012

given list a with a->b->c and where each element has a .next field reverse the list. requires three variables: next, prev, cur start by setting next to the head of the list, a. and prev to null (0) next = a prev = 0 cur = 0 loop: if (next == 0) break cur = next next = cur.next cur.next = prev prev = cur continue