-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsort_01.cpp
More file actions
37 lines (33 loc) · 720 Bytes
/
sort_01.cpp
File metadata and controls
37 lines (33 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include<iostream>
using namespace std;
void sort_01(int *arr, int n) {
int low = 0, mid = 0, high = n-1;
for (int i = 0; i < n; i++) {
int temp = arr[i];
if (arr[i] == 0) {
arr[i] = arr[left];
arr[left] = temp;
left++;
} else {
arr[i] = arr[right];
arr[right] = temp;
right--;
}
}
}
void printArray(int *arr, int n) {
for (int i = 0; i < n; i++) cout << arr[i] << " ";
cout << endl;
}
int main() {
int n;
cin >> n;
int *arr = new int[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort_01(arr, n);
printArray(arr, n);
delete []arr;
return 0;
}