Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. @SuppressWarnings("unchecked")
  2. public static boolean containsNegative(BagInterface<Integer> bag) {
  3. BagInterface<Integer> tempBag = new ArrayBag<Integer>();
  4. boolean status = false;
  5. while(!bag.isEmpty()) {
  6. int hold = bag.remove();
  7. if(hold < 0)
  8. status = true;
  9. tempBag.add(hold);
  10. }
  11. while(!tempBag.isEmpty()) {
  12. bag.add(tempBag.remove());
  13. }
  14. return status;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement