From a8e701a14c90ef6dbb280dcc2dc7109325ee6a2f Mon Sep 17 00:00:00 2001 From: Ayush Chaudhary Date: Mon, 1 Jun 2026 14:26:50 -0500 Subject: [PATCH] completed the precourse part 1 --- Exercise_1.java | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/Exercise_1.java b/Exercise_1.java index 314a3cb45..3dfec7c2f 100644 --- a/Exercise_1.java +++ b/Exercise_1.java @@ -6,30 +6,55 @@ class Stack { int a[] = new int[MAX]; // Maximum size of Stack boolean isEmpty() - { - //Write your code here + { + if(top !=0) return false; + + return true; } Stack() { - //Initialize your constructor + top = 0; } boolean push(int x) { //Check for stack Overflow //Write your code here + if(top == MAX){ + return false; + } + + top +=1; + a[top] = x; + return true; } int pop() { //If empty return 0 and print " Stack Underflow" //Write your code here + + if(top == 0){ + System.out.println("Stack Underflow"); + return 0; + } + + int num = a[top]; + top--; + return num; } int peek() { //Write your code here + if(top == 0){ + return 0; + } + + int num = a[top]; + + return num; } }