Created
March 3, 2015 05:30
-
-
Save rohith2506/fde23e1eb4e702a84494 to your computer and use it in GitHub Desktop.
Rearrange +ve and -ve elements in an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use parititon method of quick sort | |
void quick_sort(vector<int> v){ | |
int i=-1; | |
for(int j=0; j<n; j++){ | |
if(a[j] < 0){ | |
i++; | |
swap(a[i],a[j]); | |
} | |
} | |
int neg = 0, pos = i+1; | |
while(pos < n && neg < pos && a[neg] < 0){ | |
swap(a[pos], a[neg]); | |
neg = neg + 2; | |
pos = pos + 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment