Linked List

CheatSheet

find n-th node in a linked list.

// find the n-th node in the linked list
ListNode *p1 = head;
for ( int i = 1; i <= n-1; i++ ) p1 = p1->next;

count the number of nodes in a linked list

// icount is the number of nodes in a linked list
ListNode *p3 = head;
int icount = 0;
while ( p3 != NULL ) {p3 = p3->next; icount += 1;}

results matching ""

    No results matching ""