mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 12:58:42 +08:00
translation: Add Python and Java code for EN version (#1345)
* Add the intial translation of code of all the languages * test * revert * Remove * Add Python and Java code for EN version
This commit is contained in:
40
en/codes/java/chapter_stack_and_queue/stack.java
Normal file
40
en/codes/java/chapter_stack_and_queue/stack.java
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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) {
|
||||
/* Initialize stack */
|
||||
Stack<Integer> stack = new Stack<>();
|
||||
|
||||
/* Element push */
|
||||
stack.push(1);
|
||||
stack.push(3);
|
||||
stack.push(2);
|
||||
stack.push(5);
|
||||
stack.push(4);
|
||||
System.out.println("Stack stack = " + stack);
|
||||
|
||||
/* Access stack top element */
|
||||
int peek = stack.peek();
|
||||
System.out.println("Top element peek = " + peek);
|
||||
|
||||
/* Element pop */
|
||||
int pop = stack.pop();
|
||||
System.out.println("Popped element = " + pop + ", after popping" + stack);
|
||||
|
||||
/* Get the length of the stack */
|
||||
int size = stack.size();
|
||||
System.out.println("Length of the stack size = " + size);
|
||||
|
||||
/* Determine if it's empty */
|
||||
boolean isEmpty = stack.isEmpty();
|
||||
System.out.println("Is the stack empty = " + isEmpty);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user