og86

q2

Jun 5th, 2023
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. void segregateElements(int arr[],int n)
  2. {
  3. // Your code goes here
  4. vector<int> pos, neg;
  5. for(int i = 0; i < n; i++){
  6. if(arr[i] > 0) pos.push_back(arr[i]);
  7. else neg.push_back(arr[i]);
  8. }
  9. int p = 0;
  10. for(auto i: pos){
  11. arr[p] = i;
  12. p++;
  13. }
  14. for(auto i: neg){
  15. arr[p] = i;
  16. p++;
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment