employer cover photo
employer logo
employer logo

GREE International Entertainment

Est-ce votre entreprise ?

Question d’entretien chez GREE International Entertainment

Given a linked list that looks like this: Node * head; class Node { Node * next; } create a "reverse()" function that lives *within* the Node class that reverses the order of the linked list.

Réponse à la question d'entretien

Utilisateur anonyme

31 oct. 2012

@interface Node @property (nonatomic, retain) Node * next; - (Node *) reverse; @end // my attempt looked like this: - (Node *) reverse( Node * prev) { Node * nextNode = self.next; self.next = prev; if(nextNode != nil) return [ nextNode reverse: self]; else return self; } // interviewer's solution looked something like this (but not precisely, // his scribbling was way worse than mine) - (Node *) reverse: { Node * result = nil; while(current) { next = current; current.next = result; result = current; } }