Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 507 Bytes

Ex_1_3_07.md

File metadata and controls

34 lines (25 loc) · 507 Bytes
title date draft tags categories
Algorithm4 Java Solution 1.3.07
2019-07-04 05:47:10 +0800
false
JAVA
TECH
archives

1.3.07

Problem:

Add a method peek() to Stack that returns the most recently inserted item on the stack (without popping it).

Solution:

  public static void main(String[] args) {
    _Stack<Integer> s = new _Stack<>();
    s.push(1);
    s.push(2);
    s.push(3);
    s.push(4);
    assert s.peek() == 4; // pass
  }

Reference: