예제 #1
0
 @Override
 public int pop() {
   // TODO Auto-generated method stub
   ListNode temp = head;
   head = head.next;
   return temp.getVal();
 }
예제 #2
0
  @Override
  public void push(int val) {
    // TODO Auto-generated method stub
    ListNode current = new ListNode(val);

    if (head == null) {
      head = current;
    } else {
      ListNode iterNode = head;

      while (iterNode.next != null) {
        iterNode = iterNode.next;
      }

      iterNode.next = current;
    }
  }
예제 #3
0
 @Override
 public int peek() {
   // TODO Auto-generated method stub
   return head.getVal();
 }