-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueuelss.js
80 lines (67 loc) · 1.17 KB
/
queuelss.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
class Node{
constructor(val){
this.val = val;
this.next = null;
this.prev = null;
}
}
class Stack{
constructor(){
this.length = 0;
this.end= null;
this.start =null;
}
push(val){
val = new Node(val);
if(this.length === 0){
this.end = val;
this.start = val;
val.next = null;
}else {
this.end.next =val;
this.end = val;
}
this.length++;
return this;
}
pop(){
let temp = this.start;
if(this.length===0) return null;
if(this.length === 1){
this.start = null;
this.end = null;
}else{
this.start = temp.next;
}
this.length--;
return temp.val;
}
}
let chant = new Stack();
let getR = (t) => {
let result = []
let temp = t.start;
for(let i = 0; i<t.length; i++){
let nextMes = temp.next? temp.next.val : temp.next;
let msg = `${temp.val} ve ${nextMes}`;
result.push(msg);
temp = temp.next;
}
console.log(result);
}
chant.push('Siyah');
getR(chant);
chant.push('Beyaz');
getR(chant);
chant.push('En Büyük');
getR(chant);
chant.push('Altay');
getR(chant);
console.log(chant.pop());
getR(chant);
console.log(chant.pop());
getR(chant);
console.log(chant.pop());
getR(chant);
console.log(chant.pop());
getR(chant);