Thursday, April 18, 2019

Find the middle element of a Linked List


void print_middle(Node *head){
    Node *fast = head;
    Node *slow = head;
    while(fast && fast->next){
        fast = fast->next->next;
        slow = slow->next;
    }
    std::cout << slow->data << std::endl;
}

Watch the detailed explanation of the concepts on Youtube:

Subscribe to KnowledgeCenter

No comments:

Post a Comment

LeetCode 30 Day Challenge | Day 7 | Counting Elements

Given an integer array  arr , count element  x  such that  x + 1  is also in  arr . If there're duplicates in  arr , count them sepe...