📄 stacklink.java
字号:
import java.io.*;
import java.util.Scanner;
class node
{
public int data;
public node link;
}
class stacklink
{
node top;
int count;
public stacklink()
{
top=null;
count=0;
}
public void push(int id)
{
node temp=new node();
temp.data=id;
temp.link=top;
top=temp;
count++;
}
public void pop()
{
if(top==null)
System.out.println("Stack empty!");
else
{
System.out.println(top.data);
top=top.link;
count--;
}
}
public void status()
{
System.out.println("Stack contains: "+count+" elements");
node iterator=top;
for(int i=0;i<count;i++)
{
System.out.println(iterator.data);
iterator=iterator.link;
}
}
public static void main(String args[])
{
int ch;
Scanner s= new Scanner(System.in);
stack st=new stack();
do
{
System.out.println("Choose and option: \n1. PUSH\n2. POP\n3. STATUS\n4. EXIT");
System.out.print("\n\nEnter ur choice:");
ch=s.nextInt();
switch(ch)
{
case 1:
System.out.print("Enter the value to be entered :");
st.push(s.nextInt());
break;
case 2:
st.pop();
break;
case 3:
st.status();
break;
case 4:
break;
default:
System.out.println("Invalid choice!");
}
}
while(ch!=3);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -