Question: 1 . A stack is referred to as a _ _ _ _ _ _ _ _ _ _ _ _ _ ADT. 2 .

1. A stack is referred to as a _____________ ADT.
2. The process of inserting an element in a stack is called_________.
3. The process of removing an element from a stack is called_________.
4. Given Stack stack = new Stack<>(), and stack.size()=5, after a stack.push(some int) operation is performed, what would stack.size() return?
5. How many elements are in the stack after running the below code?
Stack stack = new Stack<>();
stack.push(2);
stack.pop();
stack.push(3);
stack.push(4);
stack.pop();
stack.push(5);
stack.push(6);
6. LIFO stands for_________.
7. True of False: A stack is a list of homogenous elements in which the addition and deletion of elements occurs only at one end.
8. What is printed here?
Stack stack = new Stack<>();
stack.push(22);
stack.push(90);
stack.push(46);
System.out.println(stack.pop());
9. What does the method fun do?
public static String fun(String str){
Stack stack = new Stack<>();
String res ="";
for(char c: str.toCharArray())
stack.push(c);
while(!stack.empty()){
res += stack.pop();
}
return res;
}
10. What is printed?
public class StackTest{
public static void main(String[] args){
Stack stack = new Stack();
for(int i =0; i <10; i++)
stack.push(i);
stack.pop();
stack.pop();
stack.pop();
System.out.println(stack.peek());
}
}
11. What is printed?
public class StackTest{
public static void main(String[] args){
Stack stackOne = new Stack();
Stack stackTwo = new Stack();
for(int i =0; i<5; i++)
stackOne.push(i);
stackTwo.push(stackOne.pop());
stackTwo.push(stackOne.pop());
stackTwo.push(stackOne.pop());
System.out.println (stackOne.peek());
System.out.println (stackTwo.peek());
}
}
12. What is printed?
public class Test{
public static void main(String[] args){
Stack stack = new Stack();
int n =12;
while (n >0){
stack.push(n%2);
n = n/2;
}
String result ="";
while(!stack.isEmpty())
result += stack.pop();
System.out.println(result);
}
}
13. How many elements are in each stack?
public class Test{
public static void main(String[] args){
Stack stackOne = new Stack();
Stack stackTwo = new Stack();
for(int i =0; i <100; i++)
stackOne.push(i);
for(int i =0; i <100; i++)
if(i%4==0) stackTwo.push(stackOne.peek());
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!