/
Deque.ts
104 lines (90 loc) · 3.82 KB
/
Deque.ts
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* @license
* Copyright Larry Diamond 2018 All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/larrydiamond/typescriptcollectionsframework/blob/master/LICENSE
*/
import {Collection} from "./Collection";
import {Queue} from "./Queue";
/**
* A linear collection that supports element insertion and removal at both ends.
* The name deque is short for "double ended queue" and is usually pronounced "deck".
*
* This interface extends the Queue interface. When a deque is used as a queue, FIFO (First-In-First-Out) behavior results.
* Elements are added at the end of the deque and removed from the beginning.
*
* This interface defines methods to access the elements at both ends of the deque. Methods are provided to insert, remove, and examine the element.
*
* Deques can also be used as LIFO (Last-In-First-Out) stacks. When a deque is used as a stack, elements are pushed and popped from the beginning of the deque.
*
* This interface provides two methods to remove interior elements, removeFirstOccurrence and removeLastOccurrence.
*
* This interface corresponds to java.util.Deque
*/
export interface Deque<K> extends Queue<K> {
/**
* Inserts the specified element at the front of this deque
* @param {K} k element to add
* @return {boolean} true if this collection changed as a result of the call
*/
addFirst (k:K) : boolean;
/**
* Inserts the specified element at the end of this deque
* @param {K} k element to add
* @return {boolean} true if this collection changed as a result of the call
*/
addLast (k:K) : boolean;
/**
* Inserts the specified element at the front of this deque
* @param {K} k element to add
* @return {boolean} true if this collection changed as a result of the call
*/
offerFirst (k:K) : boolean;
/**
* Inserts the specified element at the end of this deque
* @param {K} k element to add
* @return {boolean} true if this collection changed as a result of the call
*/
offerLast (k:K) : boolean;
/**
* Retrieves and removes the head of this queue. This method differs from poll only in that it returns undefined if this queue is empty
* @return {K} the element at the head of the queue or undefined if empty
*/
removeFirst () : K;
/**
* Retrieves and removes the element at the end of this queue. This method differs from poll only in that it returns undefined if this queue is empty
* @return {K} the element at the end of the queue or undefined if empty
*/
removeLast () : K;
/**
* Retrieves and removes the head of this queue, or returns null if this queue is empty.
* @return {K} the element at the head of the queue or null if empty
*/
pollFirst () : K;
/**
* Retrieves and removes the element at the end of this queue, or returns null if this queue is empty.
* @return {K} the element at the head of the queue or null if empty
*/
pollLast () : K;
/**
* Retrieves, but does not remove, the head of this queue. This method differs from peek only in that it returns undefined if this queue is empty.
* @return {K} the element at the head of the queue or undefined if empty
*/
getFirst () : K;
/**
* Retrieves, but does not remove, the last element of this queue. This method differs from peek only in that it returns undefined if this queue is empty.
* @return {K} the element at the tail of the queue or undefined if empty
*/
getLast () : K;
/**
* Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
* @return {K} the element at the head of the queue or null if empty
*/
peekFirst () : K;
/**
* Retrieves, but does not remove, the last element of this queue, or returns null if this queue is empty.
* @return {K} the element at the head of the queue or null if empty
*/
peekLast () : K;
}