Advertisement
Sanlover

Untitled

Mar 5th, 2023
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. int main()
  2. {
  3. queue<int> initial;
  4. queue<int> add;
  5. initial.push(-1);
  6. initial.push(2);
  7. initial.push(0);
  8. initial.push(4);
  9. initial.push(-5);
  10. initial.push(-6);
  11.  
  12. bool isNegativeFound = true;
  13. while (isNegativeFound)
  14. {
  15. isNegativeFound = false;
  16. for (size_t i = 0; i < initial.size(); i++)
  17. {
  18. int element = initial.front();
  19. initial.pop();
  20. if (element < 0)
  21. {
  22. add.push(element);
  23. isNegativeFound = true;
  24. }
  25. else
  26. {
  27. initial.push(element);
  28. }
  29. }
  30. }
  31.  
  32. while (!add.empty())
  33. {
  34. initial.push(add.front());
  35. add.pop();
  36. }
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement