-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoveOne's.cpp
More file actions
49 lines (45 loc) · 836 Bytes
/
moveOne's.cpp
File metadata and controls
49 lines (45 loc) · 836 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
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
using namespace std;
void printArray(vector<int> arr, int n)
{
int i = 0;
cout << endl
<< "ARRAY THUS FORMED IS : ";
while (i < n)
{
cout << arr[i++] << " ";
}
}
int main()
{
int n, i = 0, num;
cout << "Enter the number of Elements in Array : ";
cin >> n;
vector<int> arr;
cout << "Enter the Elements : ";
while (i < n)
{
cin >> num;
arr.push_back(num);
i++;
}
printArray(arr, n);
int end = arr.size() - 1;
int start = 0;
i = 1;
while (i <= end)
{
if (arr[i] == 0)
{
swap(arr[i], arr[start]);
start++;
i++;
}
else
{
swap(arr[i], arr[end]);
end--;
}
}
printArray(arr, n);
}