Pergunta de entrevista da empresa Adobe

Write an algorithm to split a circular linked list two linked list with equal no of nodes

Respostas da entrevista

Sigiloso

17 de mai. de 2012

//first points to start if the list void circular_to_list(struct node *first, struct node *second) { struct node *head, struct node *temp; head = first; second = head; first = head; do { first = first->next; if(first == temp) break; first = first->temp; second = second->next; }while(first != temp); //first is pointing to head of list //second is point to mid of the list temp = first; first = first->next; temp->next = NULL; temp = second; second = second->next; second->next = NULL; }

Sigiloso

20 de jan. de 2015

Why not this approach? 1. First find the length of the circular linked list. Let it be 'n'. 2. Then define functions as shown below. LinkedList first = toList(head, 0, len/2); LinkedList second = toList(head, (len/2)+1, len); The first argument denotes the head of circular linked list, second denotes the start and the last one denotes the tail/end of the list