Suppose there is a list s1->s2->s3->.........->sn-1
->sn. given to you. You need to modify this list in
such a way that it will be s1->sn
->s2->sn-1
->s3->sn-2.......
Note: algorithm should be inplace without modifying the values of the nodes.
Marking Scheme: Total 10 marks ( Algorithm explanation + Pseudo-code + runtime and data
structure used)
import java.util.*;
public class Main
{
public static void main(String[] args) {
List<Integer> a1 = new ArrayList<Integer>();
Scanner in=new Scanner(System.in);
a1.add(0,10);
a1.add(1,20);
a1.add(2,30);
a1.add(3,40);
a1.add(4,50);
a1.add(5,60);
System.out.println(a1);
List<Integer> a2 = new ArrayList<Integer>();
a1.set(0,10);
a1.set(1,60);
a1.set(2,20);
a1.set(3,50);
a1.set(4,30);
a1.set(5,40);
System.out.println(a1);
}
}
Comments
Leave a comment