You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
849 B
39 lines
849 B
2 years ago
|
/*
|
||
|
* To change this license header, choose License Headers in Project Properties.
|
||
|
* To change this template file, choose Tools | Templates
|
||
|
* and open the template in the editor.
|
||
|
*/
|
||
|
package lang;
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
* @author (C)Y.D.Zakovryashin, 07.11.2022
|
||
|
*/
|
||
|
public class Stack <T> {
|
||
|
|
||
|
public final int DEFAULT_SIZE = 128;
|
||
|
private T[] stack;
|
||
|
private int top;
|
||
|
|
||
|
public Stack(T[] stack) {
|
||
|
// size = size < 1 ? DEFAULT_SIZE : size;
|
||
|
this.stack = stack;
|
||
|
top = 0;
|
||
|
}
|
||
|
|
||
|
public void push(T x) throws FullStackException {
|
||
|
if (top == DEFAULT_SIZE) {
|
||
|
throw new FullStackException();
|
||
|
}
|
||
|
stack[top] = x;
|
||
|
++top;
|
||
|
}
|
||
|
|
||
|
public T pop() throws EmptyStackException {
|
||
|
if (top < 1) {
|
||
|
throw new EmptyStackException();
|
||
|
}
|
||
|
return stack[--top];
|
||
|
}
|
||
|
}
|