Answer to Question #267096 in Java | JSP | JSF for Tarurendra Kushwah

Question #267096

Create an interface and design a class to implement an interface.

1
Expert's answer
2021-11-16T13:51:02-0500
public interface Stack<T> {
  void push(T item);
  T top();
  void pop();
}
class StackIML implements Stack<T> {
  private T[] items;
  private int capacity;
  private size;

  public StackIML(int capacity) {
    this.items = new T[capacity];
    this.size = 0;
    this.capacity = capacity;  
  }

  @Override
  public void push(T item) {
    items[size++] = item;
  }
  @Override
  public T top() {
    return items[size-1];
  }
  @Override
  public void pop() {
    this.size = size - 1;
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS