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

📄 linkstack.java

📁 1. 定义链栈
💻 JAVA
字号:

public class LinkStack implements Stack
 {
 	SNode top;
 	
 	int size;
 	
 	public LinkStack()
 	{
 		top = null;
 		size = 0;
 	}
 	
 	public boolean isEmpty()//栈空
 	{
 		if(top == null)
 			return true;
 		else
 			return false;
 	}
 	
 	public boolean push(Object element)//入栈
 	{
 		SNode newSNode = new SNode(element);
 		if(top == null)
 			top = newSNode;
 		else
 		{
 			newSNode.pre = top;
 			top = newSNode;
 		}
 		size++;
 		return true;
 	}
 	
 	public Object pop()//出栈
 	{
 		SNode result = null;
 		result = top;
 		top = top.pre;
 		size--;
 		return result.data;
 	}
 	
 	public Object top()//返回当前栈顶元素
 	{
 		SNode result = top;
 		return result.data;
 	}
 	
 	public int size()//栈中当前元素的个数 
 	{
 		return size;
 	}
 	
 	public void display()
 	{
 		SNode current = top;
 		while(current != null)
 		{
 			System.out.println("  "+current.data);
 			current = current.pre;
 		}
 		
 	}
 }

⌨️ 快捷键说明

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