Sort Array Wave Form | Sorting and Searching | C++ Solution
Sort Array Wave Form, is a Sorting and Searching related problem and in this post we will see how we can solve this challenge in C++
given an array.Sort it in wave form such that a >= a <=a >= a.... can be done using:
- sort the array and swap the adjacent element after gap of 1 Tc:O(nlogn)
- we are only concerned with the even positions,where the element is supposed to be greater than preceding odd and next odd place element for all even positions: if curr < pred : swap(pred,curr) if curr < next swap(next, curr)
Please check the main.cpp snippet for the solution.
This solution originally posted at: Github by @susantabiswas