/*
Following is the Node class already written for the Linked List
class Node<T> {
T data;
Node<T> next;
public Node(T data) {
this.data = data;
}
}
*/
public class Solution {
public static void printIthNode(Node<Integer> head, int i){
while(head != null && i > 0){ //jab tak head null nhi ho jata ya i badha nhi hai 0 se tab tak loop chalana hai
head = head.next; // this is for go in next Node
i--;
if(i == 0){ //if i == o then print
System.out.print(head.data);
}
}
}
}
Comments
Post a Comment