Skip to content

Commit

Permalink
Create Move all the negative elements to one side of array.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshArya-2107 authored Oct 1, 2023
1 parent db96211 commit 3589a75
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Move all the negative elements to one side of array.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++) {
cin>>a[i];
}
int j=0;
for(int i=0;i<n;i++) {
if(a[i]<0) {
swap(a[i],a[j]);
j++;
}
}
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
}
//

0 comments on commit 3589a75

Please sign in to comment.