java - Understanding Instructions -


i'm having hard time starting lab because have no idea instruction telling me do.

instruction:

enter image description here here's have far:

public class mystack<anytype> implements stack<anytype>   {  public boolean isempty()  {     return false; } public void push(anytype x)  {     } public anytype pop()  {        return null; } public anytype peek()   {       return null;  } } 

so, thing done far create class contains interface sets methods class. have "lab 2" instructors assigned if need move java file class, can that. also, how instantiate class. (my level of understanding java low, if eli5 great).

something along lines of this:

interface istack<t> {     void push(t x);      t pop(); }  class singlylinkedlist<t> {      private class node {         t data;         node next;          public node(t data) {             this.data = data;         }     }      private node first;     private int size;      public void addfront(t x) {         node newnode = new node(x);         newnode.next = first;         first = newnode;         size++;     }      public void removefront() {         if (first == null) return;         first = first.next;         size--;     }      public t getfront() {         if (first == null) return null;         return first.data;     }      public int size() {         return size;     } }  class stack<t> implements istack<t> {      private singlylinkedlist<t> referencetothesinglylinkedlistyoumadeinlab2;      public stack() {         referencetothesinglylinkedlistyoumadeinlab2 = new singlylinkedlist<>();     }      @override     public void push(t x) {         referencetothesinglylinkedlistyoumadeinlab2.addfront(x);     }      @override     public t pop() {         t result = referencetothesinglylinkedlistyoumadeinlab2.getfront();         referencetothesinglylinkedlistyoumadeinlab2.removefront();         return result;     }      public int size() {         return referencetothesinglylinkedlistyoumadeinlab2.size();     }      public static void testclient() {         stack<string> st = new stack<>();         st.push("one");         st.push("two");         system.out.println("size: " + st.size());         system.out.println(st.pop());         system.out.println("size: " + st.size());         system.out.println(st.pop());         system.out.println("size: " + st.size());     } }  public class program {     public static void main(string[] args) {         stack.testclient();     } } 

if want can make throw exception when there no elements in stack, it's design choice.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -