Computer Science, asked by HARSHIT123RAJ, 8 months ago

Write a Java program that asks for a number (say a) and then prints A1 A2 A3 A4 and A5.​

Answers

Answered by abubakar13
4

Explanation:

Algorithm:

First swap elements in the middle pair

Next swap elements in the middle two pairs

Next swap elements in the middle three pairs

iterate n-1 steps.

Ex: with n = 4.

a1 a2 a3 a4 b1 b2 b3 b4

a1 a2 a3 b1 a4 b2 b3 b4

a1 a2 b1 a3 b2 a4 b3 b4

a1 b1 a2 b2 a3 b3 a4 b4

- X February 13, 2011 | FlagReply

1

of 1 vote

Thanks. Very simple and elegant solution :)

int interleave(int arr[], int len) {

int n = len/2;

for (int i = 1; i < n; i++) { // my step no.

for (int j = 0; j < i; j++) { // no. of swaps

swap(arr, n-i+2*j, n-i+2*j+1);

}

}

}

hope it's helpful❤❤

Mark as Brainliest

Answered by shivamyadavdeoria1
0

Explanation:

this is your answer mate

Attachments:
Similar questions