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

📄 linkstack.java

📁 从给定的字母矩阵中查找给定的字典所包含的字符串
💻 JAVA
字号:
/**
* This is the stack class for the program.
* It is made up of the linked list.  <p> 
* It can do th push, pop, peek operations as the stack requires. <p>
* It is used to store the data of the letter's position.
* 
* @author Ting Chen 0122070
* @version 1.0 2003/5/30
*/
public class LinkStack 
{

  /** The top pointer for the stack.*/
	private ListNode1 top;

  /** The number of the nodes in the stack.*/
	private int count;

 /**
	* The constructor for the class.
	* Initialize the fields as top to null and count to 0.
	*/
	public LinkStack()
	{
		top = null;
		count = 0;
	}	

	/**
	* Push the object onto the stack and return it.
	*
	* @param item The object to be pushed.
	* @return The pushed object.
	*/
	public int[] push(int[] item)
	{
		if ( top == null )
		{
			top = new ListNode1( item );
			count = 1;
			return item;
		}
		else
		{
			ListNode1 newNode = new ListNode1 ( item );
			newNode.next = top;
			top = newNode;
			count++;
			return item;
		}
		
	}

  /**
	* Pop the top object from the stack and return it.
	* 
	* @return The object poped if the stack is not empty. 
	* Or null for empty stack.
	*/
	public int[] pop()
	{
		int[] value;
		if ( count != 0)
		{
			value = top.item;
			top = top.next;
			count--;
			return value;
		}					
		return null;
	}

 /**
	* Return the top object of the stack.
	* 
	* @return The object at the top of the stack if the stack is not empty. 
	* Or null for empty stack.
	*/	
	public int[] peek()
	{		
		if ( count != 0)
			return top.item;

		return null;
	}

 /**
	* Check if the stack is empty.
	*
	* @return True for empty.  False for non-empty.
	*/
	public boolean empty()
	{
		if ( count != 0 )
		  return false;
		else
			return true;
	}

 /**
	* Give the size of the stack.
	*
	* @return The size of the stack.
	*/
	public int size()
	{
		return count;
	}	
}

⌨️ 快捷键说明

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