Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Course: EECS 114 Fall 2015
- *
- * First Name: Kevin
- * Last Name: Ngo
- * Lab Section: 1A
- * email address: kngo5@uci.edu
- *
- *
- * Assignment: assn2
- * Filename : MyQueue.java
- *
- * I hereby certify that the contents of this file represent
- * my own original individual work. Nowhere herein is there
- * code from any outside resources such as another individual,
- * a website, or publishings unless specifically designated as
- * permissible by the instructor or TA.
- */
- package assn2;
- public class MyQueue<T> {
- SimpleList<T> list;
- /*SimpleList as underlying data structure*/
- public MyQueue(SimpleList<T> list)
- {
- this.list = list;
- }
- /*Returns true of the queue is empty*/
- public boolean isEmpty()
- {
- if(list.size() == 0)
- {
- return true;
- }
- return false;
- }
- /*Inserts a value onto the rear of the queue*/
- public void push(T value)
- {
- list.insertAtPos(list.size() -1, value);
- }
- /*Remove the front item*/
- public void pop()
- {
- try
- {
- if(list.size() == 0)
- {
- String error = "pop() on MyQueue of size == 0";
- throw new QueueUnderflowException(error);
- }
- }
- catch(QueueUnderflowException e)
- {
- e.printStackTrace();
- }
- list.removeAt(0);
- }
- /*Returns the front item in the queue*/
- public T front()
- {
- try
- {
- if(list.size() == 0)
- {
- String error = "front() on MyQueue of size == 0";
- throw new QueueUnderflowException(error);
- }
- }
- catch(QueueUnderflowException e)
- {
- e.printStackTrace();
- }
- return list.getAt(0);
- }
- public int size()
- {
- return list.size();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement