MCPcopy Create free account
hub / github.com/Lakhankumawat/LearnCPP / sortInWave

Function sortInWave

A-Array/SortingInWaveForm.cpp:14–22  ·  view source on GitHub ↗

This function sorts arr[0..n-1] in wave form

Source from the content-addressed store, hash-verified

12
13// This function sorts arr[0..n-1] in wave form
14void sortInWave(int arr[], int n)
15{
16 // Sort the input array
17 sort(arr, arr+n);
18
19 // Swap adjacent elements
20 for (int i=0; i<n-1; i += 2)
21 swap(&arr[i], &arr[i+1]);
22}
23
24// Driver code
25int main()

Callers 1

mainFunction · 0.85

Calls 1

swapFunction · 0.70

Tested by

no test coverage detected