info@onlinelearningcenter.in (+91) 7 999 01 02 03 Get started with 45 Hours of Free course right now 

Arrange array in wave form

Kopal Jaiswal
29 Posts

WAP to rearrange an array in wave form.

An array said to be is sorted in wave form when -  if arr[0] >= arr[1] <= arr[2] >= arr[3] <= arr[4] >= ...

 

Example 1:

Input:  
arr[] = {10, 5, 6, 3, 2, 20, 100, 80}

 

 Output:

 arr[] = {10, 5, 6, 2, 20, 3, 100, 80} OR
         {20, 5, 10, 2, 80, 6, 100, 3} 
                 

 

Example 2: 

Input:

arr[] = {20, 10, 8, 6, 4, 2}

 Output:

arr[] = {20, 8, 10, 4, 6, 2} OR
                 {10, 8, 20, 2, 6, 4}

 Example 3:

Input:

arr[] = {2, 4, 6, 8, 10, 20}
 

 Output:

arr[] = {4, 2, 8, 6, 20, 10} OR
                 any other array that is in wave form

 

Published By : Kopal Jaiswal
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Comments