Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Practice_Questions {
- public static void main(String[] args) {
- Stack<Integer> stk1 = buildStack(1);
- Stack<Integer> stk2 = buildStack(2);
- printStack(stackOfSums(stk1, stk2));
- }
- /*
- * q2
- */
- public static Stack<Integer> digitApperance(Stack<Integer> s1){
- }
- /*
- * q1
- */
- public static Stack<Integer> stackOfSums(Stack<Integer> s1, Stack<Integer> s2){
- Stack<Integer> sumStack = new Stack<Integer>();
- return sumStack;
- }
- /*
- * builds stack for question usage
- * input - required stack by order of the questions
- */
- public static Stack<Integer> buildStack(int stack_num){
- Stack<Integer> stk = new Stack<Integer>();
- switch(stack_num) {
- case 1:
- stk.push(1);
- stk.push(4);
- stk.push(4);
- return stk;
- case 2:
- stk.push(2);
- stk.push(4);
- stk.push(3);
- return stk;
- default:
- break;
- }
- return stk;
- }
- public static int stackSize(Stack<Integer> s) {
- int count = 0;
- Stack<Integer> tmp = new Stack<Integer>();
- while(!s.isEmpty()) {
- tmp.push(s.pop());
- count++;
- }
- while(!tmp.isEmpty()) {
- s.push(tmp.pop());
- }
- return count;
- }
- public static void printStack(Stack<Integer> s) {
- Stack<Integer> tmp = new Stack<Integer>();
- while(!s.isEmpty()) {
- System.out.println("|_"+s.top()+"_|");
- tmp.push(s.pop());
- }
- while(!tmp.isEmpty()) {
- s.push(tmp.pop());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement