mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-01 11:29:51 +08:00
* docs: add Japanese documents (`ja/docs`) * docs: add Japanese documents (`ja/codes`) * docs: add Japanese documents * Remove pythontutor blocks in ja/ * Add an empty at the end of each markdown file. * Add the missing figures (use the English version temporarily). * Add index.md for Japanese version. * Add index.html for Japanese version. * Add missing index.assets * Fix backtracking_algorithm.md for Japanese version. * Add avatar_eltociear.jpg. Fix image links on the Japanese landing page. * Add the Japanese banner. --------- Co-authored-by: krahets <krahets@163.com>
40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
/**
|
|
* File: stack.java
|
|
* Created Time: 2022-11-25
|
|
* Author: krahets (krahets@163.com)
|
|
*/
|
|
|
|
package chapter_stack_and_queue;
|
|
|
|
import java.util.*;
|
|
|
|
public class stack {
|
|
public static void main(String[] args) {
|
|
/* スタックを初期化 */
|
|
Stack<Integer> stack = new Stack<>();
|
|
|
|
/* 要素をプッシュ */
|
|
stack.push(1);
|
|
stack.push(3);
|
|
stack.push(2);
|
|
stack.push(5);
|
|
stack.push(4);
|
|
System.out.println("スタック stack = " + stack);
|
|
|
|
/* スタックトップ要素にアクセス */
|
|
int peek = stack.peek();
|
|
System.out.println("スタックトップ要素 peek = " + peek);
|
|
|
|
/* 要素をポップ */
|
|
int pop = stack.pop();
|
|
System.out.println("ポップした要素 = " + pop + "、ポップ後 " + stack);
|
|
|
|
/* スタックの長さを取得 */
|
|
int size = stack.size();
|
|
System.out.println("スタックの長さ size = " + size);
|
|
|
|
/* 空かどうかを判定 */
|
|
boolean isEmpty = stack.isEmpty();
|
|
System.out.println("スタックが空か = " + isEmpty);
|
|
}
|
|
} |