Sort an array in wave form | GeeksforGeeks

preview_player
Показать описание


This video is contributed by Harshit Verma

Please Like, Comment and Share the Video among your friends.

Also, Subscribe if you haven't already! :)
Рекомендации по теме
Комментарии
Автор

this only works if all numbers are unique >

muhepei
Автор

void convertToWave(int *arr, int n)
{

int i=0;

while(i<n-1)
{
swap(arr[i], arr[i+1]);
i=i+2;
// if(i>n)
// {
// break;
// }
}

}

wecan
Автор

This solution doesn't work for [4, 5, 5, 6]. The result is [5, 4, 6, 5] which is wrong. [5, 6, 4, 5] is the valid solution

iamj
Автор

Hello, Why did you write, size of array divided by size of first element of the array?

YoshitaASharma
Автор

why did you use i<n-1? please reply.

ahmadxrizvi
Автор

For second sol, use the loop upto n-1 or it will give out of bounds error.

anshulkumar