Pergunta de entrevista da empresa Cisco

print the middle of linked list struct Node { int data; struct Node* next; }; /* Function to get the middle of the linked list*/ void printMiddle(struct Node *head) { struct Node *slow_ptr = head; struct Node *fast_ptr = head; if (head!=NULL) { while (fast_ptr != NULL && fast_ptr->next != NULL) { fast_ptr = fast_ptr->next->next; slow_ptr = slow_ptr->next; } printf("The middle element is [%d]\n\n", slow_ptr->data); }

Resposta da entrevista

Sigiloso

4 de mar. de 2019

struct Node { int data; struct Node* next; }; /* Function to get the middle of the linked list*/ void printMiddle(struct Node *head) { struct Node *slow_ptr = head; struct Node *fast_ptr = head; if (head!=NULL) { while (fast_ptr != NULL && fast_ptr->next != NULL) { fast_ptr = fast_ptr->next->next; slow_ptr = slow_ptr->next; } printf("The middle element is [%d]\n\n", slow_ptr->data); }