package stack.fy;
import java.util.Scanner;
public class StackFY {
int top=0;int[] stackData;StackFY(int n){stackData = new int[n];}void push(int x){int t = isFull();if(t==0){System.out.println("Stack is Overflow");}else{stackData[top]=x;top++;System.out.println("One Element is Pushed ");}}void pop(){int t = isEmpty();if(t==0){System.out.println("Stack is Underflow");}else{top--;System.out.println("One Element is Poped");}}void peek(){int t = isEmpty();if(t==0){System.out.println("Stack is Underflow");}else{System.out.println("One Element is Peeked "+stackData[top-1]);}}void display(){int t = isEmpty();if(t==0){System.out.println("Stack is Underflow");}else{for(int i=0;i<top;i++){System.out.println("Element -> "+stackData[i]);}}}int isEmpty(){if(top==0){return 0;}else{return 1;}}int isFull(){if(top==5){return 0;}else{return 1;}}public static void main(String[] args) {StackFY sfy = new StackFY(5);System.out.println("Welcome to the NUV\n");
System.out.println("1: Push \n2: Pop \n3: Peek \n4: Display \n5: Exit");while(5==5){Scanner obj = new Scanner(System.in);System.out.println("Enter Value ");int choice = Integer.parseInt(obj.nextLine());switch(choice){case 1:System.out.println("Enter Value");Scanner obj1 = new Scanner(System.in);int t = Integer.parseInt(obj1.nextLine());sfy.push(t);break;case 2:sfy.pop();break;case 3:sfy.peek();break;case 4:sfy.display();break;case 5:System.exit(0);default:System.out.println("Invalid Data");}}}}
import sys
class StackDemo:top = 0stackData = []size = 0
def __init__(self,size):self.size = size
def isFull(self):if(self.top==self.size):return 0else:return 1def isEmpty(self):if(self.top==0):return 0else:return 1def push(self,x):t = self.isFull()if(t==0):print("Stack is Overflow")else:self.stackData.append(x)self.top = self.top + 1print("One Element is Pushed")print(self.top)def pop(self):t = self.isEmpty()if(t==0):print("Stack is Underflow")else:self.top = self.top - 1print("One Element is Poped")print(self.top)
def peek(self):t = self.isEmpty()if(t==0):print("Stack is Underflow")else:print("One Element is Peeked",self.stackData[self.top-1])
def display(self):if(self.top == 0):print("Stack is Underflow")else:for n in range(self.top):print("Element -> ",self.stackData[n])
stack1 = StackDemo(5)choice = 0print("Welcome to the NUV\n")print("1: Push \n2: Pop \n3: Peek \n4: Display \n5: Exit")while(5==5):choice = int(input("Enter Your Choice : "))if(choice==1):t = input("Enter Value : ")stack1.push(t)elif(choice==2):stack1.pop()elif(choice==3):stack1.peek()elif(choice==4):stack1.display()elif(choice==5):sys.exit()else:print("Invalid Data")