GameNCode

DentistOffice Functions

Feb 17th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. public class Functions {
  2.  
  3. //Targil 1
  4. public static Stack<Integer> stacksToStackSums(Stack<Queue<Integer>> stackOfQueues)
  5. {
  6. int sum = 0;
  7. Queue<Integer> temp;
  8. Stack<Integer> stackSum = new Stack<Integer>();
  9.  
  10. while(!stackOfQueues.isEmpty())
  11. {
  12. sum = 0;
  13. temp = stackOfQueues.pop();
  14. while(!temp.isEmpty())
  15. {
  16. sum += temp.remove();
  17. }
  18. stackSum.push(sum);
  19. }
  20. return stackSum;
  21. }
  22.  
  23. public static boolean stackEqualsNode(Node<Character> node, Stack<Character> stack)
  24. {
  25. Stack<Character> temp = StackFunctions.duplicate(stack);
  26. while(!temp.isEmpty())
  27. {
  28. if(!NodeFunctions.isInNode(node, temp.pop()))
  29. return false;
  30. }
  31. return true;
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment