Given a linked list and an integer N, you need to find and return index where N is present in the Linked List. Return -1 if n is not present in the Linked List.
Indexing of nodes starts from 0.
Input format:
Line 1: Linked list elements (separated by space and terminated by -1)
Line 2: Integer n
Output format:
Index
Example:
Sample Input 1:
3 4 5 2 6 1 9 -1
5
Sample Output 1:
2
Sample Input 2:
3 4 5 2 6 1 9 -1
6
Sample Output 2:
4
Description:
In this question, we are given a linked list and a data. We have to find the index of the Node which contains the data.
Example:
2->1->5->4->3->NULL
In this list 5 is at 2nd index.
Algorithm:
Function:
C++ code
Output