19ELC211 DSA Lab3
19ELC211 DSA Lab3
19ELC211 DSA Lab3
LABSHEET 2 & 3
P V ADITHYAN
AM.EN.U4ELC22035
1.
}
public void display()
{
for (int i = top;i>=0;i--)
{
System.out.println(arrstack[i]);
}
}
public int pop() {
if (isEmpty()) {
System.out.println("Stack is empty");
return Integer.MIN_VALUE;
}
int poppedElement = arrstack[top--];
return poppedElement;
}
public static void main(String[] args) {
MyStack stack = new MyStack(5);
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
stack.push(5);
stack.pop();
stack.pop();
stack.display();
}
}
Output:
2.
import java.util.Stack;
import java.util.Scanner;
class Q2 {
public static boolean isBalanced(String exp) {
Stack<Character> stack = new Stack<>();
return stack.isEmpty();
}
3.
import java.util.Scanner;
class Stack {
private int top;
private int capacity;
private char[] array;
return String.valueOf(charArr);
}
}
Output:
4.
class CustomStack {
private int top;
private int capacity;
private int[] array;
while (!isEmpty()) {
int element = pop();
auxStack.push(element);
}
while (!auxStack.isEmpty()) {
int element = auxStack.pop();
System.out.print(element + " ");
push(element);
}
System.out.println();
}
}
5.
import java.util.Scanner;
class der {
private char[] stackArray;
private int top;
private int capacity;
while (!isEmpty()) {
postfix.append(pop());
}
return postfix.toString();
}
Output:
1.
pop();
stack.deleteMiddleElement();
Output:
2.
import java.util.Stack;
return stack.pop();
}