Sharp Tutorial
stack implementation in java

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

Week 1

  • Ans of Question 1
  • Ans of Question 2
  • Ans of Question 3
  • Ans of Question 4
  • Ans of Question 5

Week 2

  • Ans of Question 1
  • Ans of Question 2
  • Ans of Question 3
  • Ans of Question 4
  • Ans of Question 5

Week 3

  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5

Week 4

  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5

Week 5

  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5

Solution of java assignment questions

Stack implementation in Java

 import java.util.*;
 class Stack
 
  {
	  int st[]= new int[10];
	  int maxSize=10;
	  int top=-1;
	 
	void push(int ele)
	{
		if(top==maxSize)
		{
			System.out.println("the stack is full");
		}
		
		else
		{
			st[++top]=ele;
		}
		
	}
	
	int pop()
	{
		int ele=0;
		if(top==-1)
			System.out.println("the stack is empty");
		else{
		   ele=st[top--];
		}
		return ele;
	}
	
	void display()
	{
		for(int i=0; i<=top; i++)
		System.out.println(""+st[i]);
	}
	
  }
  
  class checkMain
  {
	  public static void main(String args[])
	  {
		  Stack s1=new Stack();
		  int ch=1,choice=0,ele=0;;
		  Scanner sc= new Scanner(System.in);
		  do{
			  System.out.println("enter choices 1:push 2:pop 3:display");
			  choice=sc.nextInt();
			  if(choice==1)
			  {
                System.out.println("enter the element to push");
                ele=sc.nextInt();				
				s1.push(ele);
	  
			  }
		      if(choice==2)
			  {
                ele=s1.pop();
				System.out.println("popped element is"+ele);
	  
			  }
			  if(choice==3)
			  {
				  s1.display();
			  }
			  System.out.println("Do you want to continue(1-Yes 0-No");
			  ch=sc.nextInt();
		   }
        while(ch==1);
	  }
  }	  

Watch video in full size

Video tutorial

Click To Read: SQL Tutorial With Easy Example Queries.

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial