-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtry.js
162 lines (120 loc) · 3.39 KB
/
try.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// // let p1 = () => console.log('1');
// // let p2 = () => console.log('2');
// // // var p3 = new Promise((resolve, reject) => {
// // // setTimeout(resolve, 100, 'foo');
// // // });
// // Promise.all([p1, p2]).then(([m1, m2]) => {
// // console.log(m1); // [3, 1337, "foo"]
// // console.log(m2); // [3, 1337, "foo"]
// // });
// // let m = [1, 2, 3, 4];
// // let q = [5, 6, 7, 8];
// // let f = [];
// // f.push(...q, ...m);
// // console.log(f);
// // function q() {
// // return function r() {
// // return function i() {
// // console.log(3);
// // };
// // };
// // };
// // console.log(q());
// // // fun[0]();
// // // fun.forEach((x) => console.log(x()));
// // let massiv = [1, 2, 3, 4, 5];
// // let qrt = massiv.map(x => {
// // return 6;
// // });
// // console.log(qrt)
// // function qoqqo() {
// // console.log('asdasd');
// // }
// // function q() {
// // return qoqqo();
// // };
// // q();
// const mas = [1, 2, 3, 4, 5];
// const ttt = [];
// // mas.forEach((x, y) => mas[y] = 1);
// // console.log(mas);
// function qqz(mas) {
// mas.forEach((v) => {
// // console.log('-------------------edno');
// // console.log(this);
// this.push(v);
// // console.log('-------------------dve');
// console.log(this);
// });
// }
// qqz(mas);
class Queue {
constructor() {
this.head = null;
this.tail = null;
this.length = 0;
}
push(...values) {
values.forEach((value) => {
const item = {
value,
next: null,
// kara: 0,
};
if (this.tail === null) {
this.head = this.tail = item;
} else {
console.log('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ');
console.log('---- PREDI this.tail.next = item; -----------');
console.log('head ---------->', this.head);
console.log('tail ---------->', this.tail);
this.head.tail = item;
console.log('---- SLED this.tail.next = item; -----------');
console.log('head ---------->', this.head);
console.log('tail ---------->', this.tail);
this.tail = item;
console.log('---- SLED this.tail = item;-----------');
console.log('head ---------->', this.head);
console.log('tail ---------->', this.tail);
console.log('QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ');
}
this.length += 1;
});
return this;
}
pop() {
if (this.head === null) {
return this;
}
const value = this.head.value;
this.head = this.head.next;
this.length -= 1;
return value;
}
peek() {
return this.head
? this.head.value
: null;
}
isEmpty() {
return !this.head;
}
}
const arr = ['edno', 'dve', 'tree'];
const m = new Queue();
m.push(...arr);
// console.log(m);
// console.log('0 pop');
// console.log(m);
// m.pop();
// console.log('1 pop');
// console.log(m);
// m.pop();
// console.log('2 pop');
// console.log(m);
// m.pop();
// console.log('3 pop');
// console.log(m);
// m.pop();
// console.log('4 pop');
// console.log(m.head);