We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
LinkedList<Integer> ll=new LinkedList<Integer>();
Scanner s=new Scanner(System.in);
Integer n=s.nextInt();
Integer a,pos;
for(Integer i=0;i<n;i++){
a=s.nextInt();
ll.addLast(a);
}
a=s.nextInt();
pos=s.nextInt();
ll.add(pos,a);
for(Integer j=0;j<ll.size();j++)
System.out.print(ll.get(j)+" ");
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Insert a node at a specific position in a linked list
You are viewing a single comment's thread. Return to all comments →
JAVA Collections Framwork import java.io.; import java.util.;
public class Solution {
}