Skip to content

Commit

Permalink
Create Prog-61.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
manushikapoor committed Jul 13, 2020
1 parent a39ca61 commit f2675e7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Prog-61.cpp
@@ -0,0 +1,21 @@
/* Binary Array Sorting */

vector<int> SortBinaryArray(vector<int> binArray)
{
int i=0,j=binArray.size()-1;
while(i<j){
while(binArray[i]==0 && i<j){
i++;
}
while(binArray[j]==1 && i<j){
j--;
}
if(binArray[i]>binArray[j]){
binArray[i]=0;
binArray[j]=1;
i++;
j--;
}
}
return binArray;
}

0 comments on commit f2675e7

Please sign in to comment.