Anzeige
Note- Help with methods public boolean remove(Object o)- public boolea.pdf
Note- Help with methods public boolean remove(Object o)- public boolea.pdf
Nächste SlideShare
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Wird geladen in ... 3
1 von 2
Anzeige

Más contenido relacionado

Similar a Note- Help with methods public boolean remove(Object o)- public boolea.pdf(20)

Más de actexerode(20)

Anzeige

Note- Help with methods public boolean remove(Object o)- public boolea.pdf

  1. Note: Help with methods public boolean remove(Object o), public boolean addAll(CiscCollection extends E> c), public Iterator iterator(), public Object[] toArray(), and public void clear(). package edu.ust.cisc; import java.util.*; public class CiscStack implements CiscCollection { /** * A reference to the node containing the element at the top of the stack (or null if stack is empty). */ private Node top; /** * Number of elements in the stack. */ private int size; /** * Inserts the specified item at the top of the stack. * * * @param item element being added to the stack * @throws NullPointerException if the item is null */ public void push(E item) { } /** * Returns and removes the element at the top of the stack. After this method finishes, {@code top} should refer to * the node containing the most recently added element (or null if no more elements remain in the stack). * * * @return the element at the top of the stack * @throws EmptyStackException if the stack is empty */ public E pop() { return null; } /** * * @return the element at the top of the stack * @throws EmptyStackException if the stack is empty */ public E peek() { return null; } /** * Returns the number of elements in this stack. * * @return the number of elements in this stack */ @Override public int size() { return 0; } /** * Returns {@code true} if this stack contains no elements. * * @return {@code true} if this stack contains no elements */ @Override public boolean isEmpty() { return false; } /** * Returns {@code true} if this stack contains the specified element (compared using the {@code equals} * method). * * @param o element whose presence in this stack is to be tested * @return {@code true} if this stack contains the specified element * @throws NullPointerException if the specified element is null */ @Override public boolean contains(Object o) { if(o==null){ throw new NullPointerException(); } Node node = top; while(node!=null) { if (node.data.equals(o)) { return true; } node = node.next; } return false; } /** * Inserts the specified item at the top of the stack. See the {@code push} operation. * * @param e element being added to the stack * @return {@code true} * @throws NullPointerException if the item is null */ @Override public boolean add(E e) { return false; } /** * This operation is not supported by CiscStack. * * @param o element to be removed from this collection, if present * @return {@code true} if this collection contained the specified element * @throws UnsupportedOperationException if the {@code remove} operation is not supported by this collection */ @Override public boolean remove(Object o) { return false; } /** * Adds all elements in the specified collection to this stack, in the order that they are returned by the * specified collection's iterator. * * @param c collection containing elements to be added to this stack * @return {@code true} if this stack changed as a result of the call * @throws NullPointerException if the specified collection is null */ @Override public boolean addAll(CiscCollection extends E> c) { return false; } /** * Returns an iterator over the elements in this stack from top to bottom. * * @return an iterator over the elements in this stack from top to bottom */ @Override public Iterator iterator() { return null; } /** * Returns an array containing all of the elements in this stack in proper sequence (from top to bottom). * * The returned array will be "safe" in that no references to it are maintained by this stack. The caller is * thus free to modify the returned array. * * @return an array containing all of the elements in this stack in proper sequence */ @Override public Object[] toArray() { return new Object[0]; } /** * Removes all of the elements from this stack. The stack will be empty after this call returns. */ @Override public void clear() { } /** * Returns a string representation of this stack. This string should consist of a comma separated list of * values contained in this stack, from top to bottom, surrounded by square brackets (examples: [3, 6, 7] and []). * * @return a string representation of this stack */ public String toString() { return null; } private static class
  2. Node { private E data; private Node next; private Node(E data, Node next) { this.data = data; this.next = next; } } private static class CiscStackIterator implements Iterator { /** * A reference to the node containing the next element to return. */ private Node nextNode; /** * Constructs an iterator beginning at the specified node. */ private CiscStackIterator(Node top) { } /** * Returns {@code true} if the iteration has more elements. (In other words, returns {@code true} if * {@link #next} would return an element rather than throwing an exception.) * * @return {@code true} if the iteration has more elements */ @Override public boolean hasNext() { return false; } /** * Returns the next element in the iteration. * * @return the next element in the iteration * @throws NoSuchElementException if the iteration has no more elements */ @Override public E next() { return null; } } }
Anzeige