Update OddEven Sort.cpp

This commit is contained in:
Ashwek Swamy 2019-02-10 11:20:09 +05:30 committed by GitHub
parent ef377b0807
commit a73dc04f0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,15 +1,10 @@
/* C++ implementation Odd Even Sort */
#include <iostream>
#include <vector>
using namespace std;
void switchElmts(int arr[], int i, int j)
{
int tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
void oddEven(int arr[], int size)
void oddEven(vector<int> &arr, int size)
{
bool sorted = false;
while( ! sorted )
@ -19,7 +14,7 @@ void oddEven(int arr[], int size)
{
if(arr[i] > arr[i+1])
{
switchElmts(arr,i,i+1);
swap(arr[i], arr[i+1]);
sorted = false;
}
}
@ -28,14 +23,14 @@ void oddEven(int arr[], int size)
{
if(arr[i] > arr[i+1])
{
switchElmts(arr,i,i+1);
swap(arr[i], arr[i+1]);
sorted = false;
}
}
}
}
void show(int A[], int size)
void show(vector<int> A, int size)
{
int i;
for (i = 0; i < size; i++)
@ -45,19 +40,18 @@ void show(int A[], int size)
int main()
{
int size;
int size, temp;
cout << "\nEnter the number of elements : ";
cin >> size;
int arr[size];
vector<int> arr;
cout<<"\nEnter the unsorted elements : ";
cout<<"\nEnter the unsorted elements : \n";
for (int i = 0; i < size; ++i)
{
cout<<"\n";
cin>>arr[i];
cin >> temp;
arr.push_back(temp);
}
oddEven(arr, size);