Answer to Question #230346 in Java | JSP | JSF for Anonymous

Question #230346

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)


1
Expert's answer
2021-08-28T01:35:42-0400
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);
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS