We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
#include <iostream>
using namespace std;
void BubbleSort(int arr[], int n) { for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { // Swap arr[j] and arr[j + 1] int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } } void SortInwave(int arr[], int n) { // creating wave pattern for (int i = 0; i < n - 1; i += 2) { int temp; temp=arr[i]; arr[i]=arr[i+1]; arr[i+1]=temp; } }
int main() { int arr[] = {3,78,44,91,1,34,6}; int n = sizeof(arr) / sizeof(arr[0]); //arranging into ascending order and applying wave BubbleSort(arr,n); SortInwave(arr, n);
cout << "Wave array: ";
for (int i = 0; i < n; i++) { cout << arr[i] << " "; } cout << endl;