Kaynağa Gözat

Created and tested Project 3

Tom Flucke 10 yıl önce
ebeveyn
işleme
512a0ac296

+ 6 - 0
Project3/.classpath

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

+ 17 - 0
Project3/.project

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>Project3</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

+ 11 - 0
Project3/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8

+ 577 - 0
Project3/src/BST.java

@@ -0,0 +1,577 @@
+/**
+ * Binary Search Tree using the Comparable interface.
+ * Contains classes BSTNode, PreIter, InIter, LevelIter
+ * 
+ * Project 3
+ * 
+ * @author Thomas Flucke tflucke
+ * @author Lara Luu ljluu
+ * 
+ * @since 2015/11/1
+ * 
+ * @see Comparable
+ */
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+public class BST <T extends Comparable <? super T>>
+{
+	/**
+	 * A private class used by BST
+	 * Creates Nodes to be used in the tree consisting of a left child (type BSTNode), a right child (type BSTNode), and an element type T
+	 * 
+	 * Project 3
+	 * 
+	 * @author Thomas Flucke tflucke
+	 * @author Lara Luu ljluu
+	 * 
+	 * @since 2015/11/2
+	 */
+	
+	private class BSTNode
+	{
+		/**
+		 * Contains the element in this node of the tree
+		 */
+		private T element;
+		
+		/**
+		 * The link to the left subtree
+		 */
+		private BSTNode leftChild;
+		
+		/**
+		 * The link to the right subtree
+		 */
+		private BSTNode rightChild;
+
+		/**
+		 * Creates a node with the given element as the value
+		 * 
+		 * @param element The node's value
+		 */
+		private BSTNode(T element)
+		{
+			this.element = element;
+		}
+	}
+	/**
+	 * The BSTNode containing the beginning of the tree. 
+	 */
+	private BSTNode root;
+	
+	/**
+	 * A private class used by BST
+	 * Creates a stack that organizes the BST by preorder traversal
+	 * 
+	 * Project 3
+	 * 
+	 * @author Thomas Flucke tflucke
+	 * @author Lara Luu ljluu
+	 * 
+	 * @since 2015/11/2
+	 */
+	
+	private class PreIter implements Iterator<T>
+	{
+		/**
+		 * The stack that contains the elements in the tree 
+		 */
+		public MyStack<BSTNode> stk;
+		
+		/**
+		 * Constructor creating the stack out of the BST, pushes the root onto the tree
+		 */
+		public PreIter()
+		{
+			stk = new MyStack<BSTNode>();
+			if (root != null)
+			{
+				stk.push(root);
+			}
+		}
+		
+		/**
+		 * Method returning a boolean stating whether or not there is a next element
+		 */
+		@Override
+		public boolean hasNext()
+		{	
+			return (!stk.isEmpty());
+		}
+		
+		/**
+		 * Method returns the next element in the preorder traversal
+		 */
+		@Override
+		public T next() 
+		{
+			if(!hasNext())
+			{
+				throw new NoSuchElementException();
+			}
+			
+			/*
+			 * Temporary variable holding the value of the popped node
+			 */
+			BSTNode tmp = stk.pop();
+			if (tmp.rightChild != null)
+			{
+				stk.push(tmp.rightChild);
+			}
+			if (tmp.leftChild != null)
+			{
+				stk.push(tmp.leftChild);
+			}
+			
+			return tmp.element;
+		}
+	}
+	
+	/**
+	 * A private class used by BST
+	 * Creates a stack that organizes the BST by infix traversal
+	 * 
+	 * Project 3
+	 * 
+	 * @author Thomas Flucke tflucke
+	 * @author Lara Luu ljluu
+	 * 
+	 * @since 2015/11/2
+	 */
+	
+	private class InIter implements Iterator<T>
+	{
+		/**
+		 * The stack that contains the elements in the tree 
+		 */
+		public MyStack<BSTNode> stk;
+		
+		/**
+		 * Constructor creating the stack out of the BST, pushes the root onto the tree
+		 */
+		public InIter()
+		{
+			stk = new MyStack<BSTNode>();
+			BSTNode chkNode = root;
+			while (chkNode != null)
+			{
+				stk.push(chkNode);
+				chkNode = chkNode.leftChild;
+			}
+		}
+		
+		/**
+		 * Method returning a boolean stating whether or not there is a next node
+		 */
+		@Override
+		public boolean hasNext()
+		{
+			return(!stk.isEmpty());
+		}
+		
+		/**
+		 * Method returns the next element in the infix traversal
+		 */
+		@Override
+		public T next() 
+		{
+			if(!hasNext())
+			{
+				throw new NoSuchElementException();
+			}
+			/*
+			 * Temporary variable holding the value of the popped node
+			 */
+			BSTNode tmp = stk.pop();
+			/*
+			 * Current left most node of the right subtree to be added to the stack
+			 */
+			BSTNode chkNode = tmp.rightChild;
+			while(chkNode != null)
+			{
+				stk.push(chkNode);
+				chkNode = chkNode.leftChild;
+			}
+			return tmp.element;
+		}
+		
+	}
+	
+	/**
+	 * A private class used by BST
+	 * Creates a queue that organizes the BST by level
+	 * 
+	 * Project 3
+	 * 
+	 * @author Thomas Flucke tflucke
+	 * @author Lara Luu ljluu
+	 * 
+	 * @since 2015/11/2
+	 */
+	private class LevelIter implements Iterator<T>
+	{
+		/**
+		 * The queue that contains the elements in the tree 
+		 */
+		private LQueue<BSTNode> queue;
+		
+		/**
+		 * Constructor creating the queue out of the BST, pushes the root onto the tree
+		 */
+		public LevelIter()
+		{
+			queue = new LQueue<BSTNode>();
+			if(root != null)
+			{
+				queue.enqueue(root);
+			}
+		}
+
+		/**
+		 * Returning a boolean stating whether or not there is a next node
+		 */
+		@Override
+		public boolean hasNext() 
+		{
+			return !queue.isEmpty();
+		}
+
+		/**
+		 * Returns the next element in the in-level traversal
+		 */
+		@Override
+		public T next() 
+		{
+			/*
+			 * Temporary variable holding the value of the dequeued node
+			 */
+			BSTNode tmp = queue.dequeue();
+			if(tmp.leftChild != null)
+			{
+				queue.enqueue(tmp.leftChild);
+			}
+			if(tmp.rightChild != null)
+			{
+				queue.enqueue(tmp.rightChild);
+			}
+			return tmp.element;
+		}
+	}
+
+	/**
+	 * An exception to be thrown when an invalid operation is invoked while the heap is empty.
+	 * Basically a carbon-copy of RuntimeException
+	 * 
+	 * Project 3
+	 * 
+	 * @author Thomas Flucke tflucke
+	 * @author Lara Luu ljluu
+	 * 
+	 * @since 2015/11/2
+	 */
+	@SuppressWarnings("serial")
+	public static class MyException extends RuntimeException
+	{
+		/**
+		 * Default constructor which just calls the super constructor.
+		 */
+		public MyException()
+		{
+			super();
+		}
+
+		/**
+		 * Constructor which just passes a string argument to the super constructor.
+		 */
+		public MyException(String msg)
+		{
+			super(msg);
+		}
+	}
+	
+	/**
+	 * Constructor initializes an empty binary search tree
+	 */
+	public BST()
+	{
+		root = null;
+	}
+	
+	/**
+	 * Method to insert a T element into the BST
+	 */
+	public void insert(T item)
+	{
+		root = insertHelper(root, item);
+	}
+	
+	/**
+	 * returns BSTNode after adding the new member in the correct location
+	 */
+	private BSTNode insertHelper(BSTNode chkNode, T item)
+	{
+		if (chkNode == null)
+		{
+			return new BSTNode(item);
+		}
+		if(item.compareTo(chkNode.element) < 0)
+		{
+			chkNode.leftChild = insertHelper(chkNode.leftChild, item);
+		}
+		else
+		{
+			chkNode.rightChild = insertHelper(chkNode.rightChild, item);
+		}
+		return chkNode;
+	}
+	
+	/**
+	 * Finds the element specified in the BST and deletes it
+	 */
+	public void delete(T item)
+	{
+		root = deleteFindHelper(root, item);
+	}
+	
+	/**
+	 * locates the element to be deleted, runs deleteNode to delete the node
+	 */
+	private BSTNode deleteFindHelper(BSTNode chkNode, T item)
+	{
+		if(chkNode == null)
+		{
+			return null;
+		}
+		else if(chkNode.element.compareTo(item) == 0)
+		{
+			return deleteNode(chkNode);
+			
+		}
+		else if(item.compareTo(chkNode.element) < 0)
+		{
+			chkNode.leftChild = deleteFindHelper(chkNode.leftChild, item);
+		}
+		else
+		{
+			chkNode.rightChild = deleteFindHelper(chkNode.rightChild, item);
+		}
+		return chkNode;
+	}
+	
+	/**
+	 * returns a node after circulating through the BST to delete the found element
+	 */
+	private BSTNode deleteNode(BSTNode deleteNode)
+	{
+		//Node has no children
+		if (deleteNode.leftChild == null && deleteNode.rightChild == null)
+		{
+			return null;
+		}
+		//Node has one child
+		if(deleteNode.leftChild != null && deleteNode.rightChild == null)
+		{
+			return deleteNode.leftChild;
+		}
+		else if( deleteNode.rightChild != null && deleteNode.leftChild == null)
+		{
+			return deleteNode.rightChild;
+		}
+		//Node has two children
+		else
+		{
+			BSTNode chkNode = deleteNode.rightChild;
+			while (chkNode.leftChild != null)
+			{
+				chkNode = chkNode.leftChild;
+			}
+			deleteNode.element = chkNode.element;
+			deleteNode(chkNode);
+			return deleteNode;
+		}
+
+	}
+	
+	/**
+	 * Returns a boolean stating whether or not an item is found in the BST
+	 */
+	public boolean find(T item)
+	{
+		return findHelper(root, item);
+	}
+	
+	/**
+	 * Recurses through BST in order to search for the item to be found
+	 */
+	private boolean findHelper(BSTNode chkNode, T item)
+	{
+		if (chkNode == null)
+		{
+			return false;
+		}
+		else if (chkNode.element.compareTo(item) == 0)
+		{
+			return true;
+		}
+		else if (item.compareTo(chkNode.element) < 0)
+		{
+			return findHelper(chkNode.leftChild, item);
+		}
+		else
+		{
+			return findHelper(chkNode.rightChild, item);
+		}
+		
+	}
+	
+	/**
+	 * returns a boolean stating whether or not the tree is empty
+	 */
+	public boolean isEmpty()
+	{
+		return root == null;
+	}
+	
+	/**
+	 * deletes the old BST, creating a new one in its place
+	 */
+	public void makeEmpty()
+	{
+		root = null;
+	}
+	
+	/**
+	 * returns the number of elements in the tree
+	 */
+	public int size()
+	{
+		return sizeHelper(root);
+		
+	}
+	
+	/**
+	 * recurses through the tree to count the number of elements in it
+	 */
+	private int sizeHelper(BSTNode chkNode)
+	{
+		if (chkNode == null)
+		{
+			return 0;
+		}
+		else
+		{
+			return 1 + sizeHelper(chkNode.leftChild) + sizeHelper(chkNode.rightChild);
+		}
+	}
+	
+	/**
+	 * returns the smallest element in the tree
+	 */
+	public T findMinimum()
+	{
+		if(root == null)
+		{
+			throw new MyException();
+		}
+		/*
+		 * holds the min node in the tree
+		 */
+		BSTNode chkNode = root;
+		while(chkNode.leftChild != null)
+		{
+			chkNode = chkNode.leftChild;
+		}
+		return chkNode.element;
+	}
+	
+	/**
+	 * returns the largest element in the tree
+	 */
+	public T findMaximum()
+	{
+		if (root == null)
+		{
+			throw new MyException();
+		}
+		/*
+		 * holds the max node in the tree
+		 */
+		BSTNode chkNode = root;
+		while(chkNode.rightChild != null)
+		{
+			chkNode = chkNode.rightChild;
+		}
+		return chkNode.element;
+	}
+	
+	/**
+	 * Constructor creating a preOrder stack
+	 */
+	public Iterator<T> iteratorPre()
+	{
+		return new PreIter();
+	}
+	
+	/**
+	 * Constructor creating a infixOrder stack
+	 */
+	public Iterator<T> iteratorIn()
+	{
+		return new InIter();
+	}
+	
+	/**
+	 * Constructor creating a levelOrder stack
+	 */
+	public Iterator<T> iteratorLevel()
+	{
+		return new LevelIter();
+	}
+
+	/**
+	 * Method printing out all the elements in the tree
+	 */
+	public void printTree()
+	{
+		printHelper(root, "");
+	}
+	
+	/**
+	 * Recursive method creating the formatting for and printing the tree
+	 */
+	private void printHelper(BSTNode chkNode, String indent)
+	{
+		if (chkNode != null)
+		{
+			System.out.println(indent + chkNode.element);
+			indent += "    ";
+			printHelper(chkNode.leftChild, indent);
+			printHelper(chkNode.rightChild, indent);
+		}
+	}
+	
+	/**
+	 * Method creating a single-line string out of the binary tree
+	 */
+	@Override
+	public String toString()
+	{
+		return stringHelper(root);
+	}
+	
+	/**
+	 * Recursive method helping to form the string with proper formatting 
+	 */
+	private String stringHelper(BSTNode chkNode)
+	{
+		if (chkNode == null)
+		{
+			return "";
+		}
+		String left = stringHelper(chkNode.leftChild);
+		String right = stringHelper(chkNode.rightChild);
+		return (chkNode.element + (left.length() > 0? " "+left:"") + (right.length() > 0? " "+right:"") );
+	}
+}

+ 161 - 0
Project3/src/BSTDriver.java

@@ -0,0 +1,161 @@
+/**
+ * Driver program to allow command line user to interface with the BST class.
+ * 
+ * Project 3
+ * 
+ * @author Thomas Flucke tflucke
+ * @author Lara Luu ljluu
+ * 
+ * @since 2015/11/02
+ * 
+ * @see BST
+ */
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+import java.util.Scanner;
+
+public class BSTDriver
+{
+	/**
+	 * Runs the program.
+	 */
+	public static void main(String...strings)
+	{
+		//Console input
+		Scanner in = new Scanner(System.in);
+		//Tree to store the inputs
+		BST<Integer> tree = new BST<Integer>();
+		System.out.println("Choose one of the following operations by entering provided letter:");
+		System.out.println("a - add the element");
+		System.out.println("d - delete the element");
+		System.out.println("f - find the element");
+		System.out.println("e - check if the tree is empty");
+		System.out.println("k - make the tree empty");
+		System.out.println("n - get the number of nodes (the size) of the tree");
+		System.out.println("m - find the minimal element");
+		System.out.println("x - find the maximal element");
+		System.out.println("p - print the tree in preorder using iterator");
+		System.out.println("i - print the tree in inorder using iterator");
+		System.out.println("l - print the tree in levelorder using iterator");
+		System.out.println("t - print the tree using printTree");
+		System.out.println("o - output the tree using toString");
+		System.out.println("q - Quit the program");
+		//Remains true as long as the user doesn't quit.
+		boolean running = true;
+		while (running)
+		{
+			System.out.println("Enter a menu choice: ");
+			//The current line which should contain the command
+			String line = in.nextLine();
+			if (line.length() != 1)
+			{
+				System.out.println("Invalid choice");
+				continue;
+			}
+			//The one character command inputed
+			char command = line.charAt(0);
+			switch (command)
+			{
+				case 'a':
+					System.out.println("Enter a value:");
+					// Value to be inserted into the tree
+					int newVal = in.nextInt();
+					tree.insert(newVal);
+					System.out.println(newVal+" inserted");
+					in.nextLine();
+					break;
+				case 'd':
+					try
+					{
+						System.out.println("Enter a value:");
+						// Value to be deleted from the tree
+						int oldVal = in.nextInt();
+						tree.delete(oldVal);
+						System.out.println(oldVal+" deleted");
+						in.nextLine();
+					}
+					catch (NoSuchElementException nsee)
+					{
+					}
+					break;
+				case 'f':
+					System.out.println("Enter a value:");
+					// Value to be found (or not) in the tree
+					int findVal = in.nextInt();
+					System.out.println(findVal+(tree.find(findVal)? " is in the tree":" is not in the tree"));
+					in.nextLine();
+					break;
+				case 'e':
+					System.out.println(tree.isEmpty()? "tree is empty":"tree is not empty");
+					break;
+				case 'k':
+					tree.makeEmpty();
+					System.out.println("tree is now empty");
+					break;
+				case 'n':
+					System.out.println("there are "+tree.size()+" nodes in the tree");
+					break;
+				case 'm':
+					try
+					{
+						System.out.println("the minimum element is "+tree.findMinimum());
+					}
+					catch (BST.MyException me)
+					{
+						System.out.println("Tree is empty");
+					}
+					break;
+				case 'x':
+					try
+					{
+						System.out.println("the maximum element is "+tree.findMaximum());
+					}
+					catch (BST.MyException me)
+					{
+						System.out.println("Tree is empty");
+					}
+					break;
+				case 'p':
+					// Iterator that gets each element in pre-order
+					Iterator<Integer> preIter = tree.iteratorPre();
+					while (preIter.hasNext())
+					{
+						System.out.print(preIter.next()+(preIter.hasNext()?" ":""));
+					}
+					System.out.println();
+					break;
+				case 'i':
+					// Iterator that gets each element in in-order
+					Iterator<Integer> inIter = tree.iteratorIn();
+					while (inIter.hasNext())
+					{
+						System.out.print(inIter.next()+(inIter.hasNext()?" ":""));
+					}
+					System.out.println();
+					break;
+				case 'l':
+					// Iterator that gets each element in level-order
+					Iterator<Integer> lvlIter = tree.iteratorLevel();
+					while (lvlIter.hasNext())
+					{
+						System.out.print(lvlIter.next()+(lvlIter.hasNext()?" ":""));
+					}
+					System.out.println();
+					break;
+				case 't':
+					tree.printTree();
+					break;
+				case 'o':
+					System.out.println(tree);
+					break;
+				case 'q':
+					running = false;
+					System.out.println("Quitting");
+					break;
+				default:
+					System.out.println("Invalid Option.");
+			}
+		}
+		in.close();
+	}
+}

+ 58 - 0
Project3/src/DictionaryMaker.java

@@ -0,0 +1,58 @@
+/**
+ * Reads words from a file, ignoring duplicates, and prints them in ascending lexicographical order.
+ * Inputs must be whitespace seperated
+ * 
+ * Project 3
+ * 
+ * @author Thomas Flucke tflucke
+ * @author Lara Luu ljluu
+ * 
+ * @since 2015/11/2
+ * 
+ * @see BST
+ */
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Scanner;
+
+public class DictionaryMaker
+{
+	/**
+	 * Runs the program.
+	 */
+	public static void main(String[] args) throws FileNotFoundException
+	{
+		//Console input
+		Scanner consoleIn = new Scanner(System.in);
+		System.out.println("Salutations. Please enter the file name to be read.");
+		// Reads the file from the filename provided in the commnd line
+		Scanner fileIn = new Scanner(new File(consoleIn.nextLine()));
+		System.out.println("Please enter the file name to be outputed.");
+		//Creates the file with the completed dictionary
+		PrintWriter fileOut = new PrintWriter(consoleIn.nextLine());
+		consoleIn.close();
+
+		//Tree to store the words
+		BST<String> wordTree = new BST<String>();
+		
+		while (fileIn.hasNext())
+		{
+			//Store the next word from the input file
+			String word = fileIn.next();
+			if (!wordTree.find(word))
+			{
+				wordTree.insert(word);
+			}
+		}
+		fileIn.close();
+		//Iteratorates over each word in lexigraphical order
+		Iterator<String> wordSorted = wordTree.iteratorIn();
+		while (wordSorted.hasNext())
+		{
+			fileOut.println(wordSorted.next());
+		}
+		fileOut.close();
+	}
+}

+ 70 - 0
Project3/src/LQueue.java

@@ -0,0 +1,70 @@
+
+public class LQueue<T>
+{
+	public static class MyException extends RuntimeException
+	{
+		private static final long serialVersionUID = -244806549310243756L;
+		public MyException()
+		{
+			super();
+		}
+		public MyException(String message)
+		{
+			super(message);
+		}
+	}
+	
+	private Node front, end;
+	
+	public LQueue()
+	{
+		front = end = null;
+	}
+	
+	public void enqueue(T item)
+	{
+		Node newEnd = new Node(item);
+		if (isEmpty())
+		{
+			front = newEnd;
+		}
+		else
+		{
+			end.next = newEnd;	
+		}
+		end = newEnd;
+	}
+	
+	public T dequeue()
+	{
+		if (isEmpty())
+		{
+			throw new MyException();
+		}
+		try
+		{
+			return front.item;
+		}
+		finally
+		{
+			front = front.next;
+		}
+	}
+	
+	public boolean isEmpty()
+	{
+		return front == null;
+	}
+	
+	private class Node
+	{
+		public T item;
+		public Node next;
+		
+		public Node(T item)
+		{
+			this.item = item;
+			this.next = null;
+		}
+	}
+}

+ 83 - 0
Project3/src/MyStack.java

@@ -0,0 +1,83 @@
+/**
+ * Linked list implementation of a stack.
+ * 
+ * Project 3
+ * 
+ * @author Thomas Flucke tflucke
+ * @author Lara Luu ljluu
+ * 
+ * @since 2015/11/02
+ */
+
+import java.util.EmptyStackException;
+public class MyStack<T>
+{
+	/**
+	 * A single node containing an item in the list and a reference to the next node.
+	 */
+	private class Node
+	{
+		public T elm; // contains the data in the node
+		
+		public Node next; // contains the location of the next linked node
+	}
+	
+	private Node first; // contains the first node in the linked list
+	
+	/**
+	 * Initializes an instance of MyStack
+	 */
+	public MyStack()
+	{
+		first = null;
+	}
+	
+	/**
+	 * Places an item at the front of the stack.
+	 * @param item The item to be placed on the stack.
+	 */
+	public void push(T item)
+	{
+		Node newFirst = new Node(); // creates a new node
+		newFirst.elm = item; 
+		newFirst.next = first; 
+		first = newFirst; 
+	}
+
+	/**
+	 * Removes an item from the front of the stack.
+	 * @return The item removed from the stack.
+	 */
+	public T pop()
+	{
+		if (isEmpty())
+		{
+			throw new EmptyStackException();
+		}
+		T val = first.elm; // stores object to be returned
+		first = first.next;
+		return val;
+	}
+	
+	/**
+	 * Returns the value at the front of the stack.
+	 * @return The item at the front of the stack.
+	 */
+	public T peek()
+	{
+		if (isEmpty())
+		{
+			throw new EmptyStackException();
+		}
+		return first.elm;
+	}
+	
+	/**
+	 * Checks if there are any items left on the stack.
+	 * @return true if there are no items on the stack, false otherwise.
+	 */
+	public boolean isEmpty()
+	{
+		return first == null;
+	}
+}