Cocktail Sort In C/C++
TechnoPhasePRO opened this issue · 4 comments
Description
Cocktail Sort in c.
Domain
C/CPP
Type of Contribution
Documentation
Code of Conduct
- I follow Contributing Guidelines & Code of conduct of this project.
/assign
Hello @TechnoPhasePRO,
Thank you for opening an issue.
Note - Self-assigns by the original author will be prioritised by mentors manually
To get assigned to this particular issue please use /assign
Check this guide before contributing.
This issue has been assigned to @TechnoPhasePRO!
It will become unassigned if it isn't closed within 12 days. A maintainer can also add the pinned label to prevent it from being unassigned.
#include
using namespace std;
int main() {
int arr[] = { 5, 3, 4, 2, 1 };
int m=5;
int n, c;
n=m;
do {
for (int i = 0; i < n - 1; i++) {
if (arr[i] > arr[i + 1]) {
arr[i] = arr[i] + arr[i + 1];
arr[i + 1] = arr[i] - arr[i + 1];
arr[i] = arr[i] - arr[i + 1];
}
}
n = n - 1;
for (int i=m-1, c = 0; i >= c; i--) {
if(arr[i] < arr[i - 1]) {
arr[i] = arr[i] + arr[i - 1];
arr[i - 1] = arr[i] - arr[i - 1];
arr[i] = arr[i] - arr[i - 1];
}
}
c = c + 1;
}
while (n != 0 && c != 0);
for (int i = 0; i < m; i++) {
cout<< arr[i]<<"\t";
}
}
Is it true??