-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.java
84 lines (63 loc) · 1.4 KB
/
Stack.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.EmptyStackException;
/**
* Esta clase hace un stack
*
* @author estefy
*
* @param <T> contenido
*
* @version 1.0
*/
import java.util.concurrent.LinkedBlockingQueue;
public class Stack<T> {
StackNode<T> last;
public StackMio(){
this.last=new StackNode<T>(null);
}
public StackMio(T value){
this.last= new StackNode<T>(value);
}
public T peek(){
if(isEmpty()){
throw new EmptyStackException();
}
return (T) this.last.value;
}
public T pop(){
if(peek()==null){
throw new EmptyStackException();
}
StackNode<T> temp=new StackNode<T>(last.value);
this.last=last.next;
return temp.value;
}
public void push(T nodo){
StackNode<T> nuevo= new StackNode<T>(nodo);
nuevo.next=last;
this.last=nuevo;
}
public boolean isEmpty(){
return this.last==null;
}
private class StackNode<T>{
protected T value;
protected StackNode<T> next;
public StackNode(T value){
this.value=value;
this.next=null;
}
}
public static void main(String[] args) {
StackMio<String> stack=new StackMio<String>();
stack.push("Estefy");
stack.push("Edgar");
LinkedBlockingQueue<String> queue=new LinkedBlockingQueue<String>(3);
queue.add("Estefy");
queue.peek();
queue.add("edgar");
Object [] array= new Object[4];
array= queue.toArray();
System.out.println(array[1]);
//System.out.println(queue.toString());
}
}