⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stackimp.java

📁 many simple java programs like classic algorithems to do search and few data structure implimentatio
💻 JAVA
字号:
import java.io.*;
import java.util.Scanner;

class node
  {
    public int data;
    node link;
  }
  
 class stack
{
  private node top;
    
  public stack()
  {
     top=null;
  }
    
  public void push(int data)
  {
    node t;
    t=new node();
    if(t==null)
       System.out.println("Stack Full! ");
     else
       {
         t.data=data;
         t.link=top;
         top=t;
       }
  }
     
  public int pop()
  {
    if(top==null)
    {
      System.out.println("Stack is empty!");
      return 0;
    }
    else
    {
      int data;
      node temp=top;
      data=top.data;
      top=top.link;
      return data;
    }
  }

}
public class stackimp
{
  
  
   public static void main(String args[])
   {
      stack st=new stack();
      Scanner s=new Scanner(System.in);
      int ch;
      do 
      {
       System.out.println("What would u like to do ? 1) push 2) pop ");
      
       ch=s.nextInt();
       if(ch==1) 
       {
          System.out.println("Enter teh value to be pushed : ");
          int data=s.nextInt();
           st.push(data);
        } 
        else
          if(ch==2)
             System.out.println("Stack top="+st.pop());     
       }while (ch!=3);   
      } 
 }
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -