File tree Expand file tree Collapse file tree 2 files changed +14
-14
lines changed Expand file tree Collapse file tree 2 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,11 @@ export class Lesson12 {
20
20
}
21
21
22
22
if ( oddPoints > evenPoints ) {
23
- return " Odd" ;
23
+ return ' Odd' ;
24
24
} else if ( evenPoints > oddPoints ) {
25
- return " Even" ;
25
+ return ' Even' ;
26
26
} else {
27
- return " Tie" ;
27
+ return ' Tie' ;
28
28
}
29
29
}
30
30
}
Original file line number Diff line number Diff line change 1
1
import { ListNode } from './list_node.js' ;
2
2
3
3
export class Stack {
4
- private top : ListNode | null ;
4
+ private top : ListNode | undefined ;
5
5
6
6
constructor ( ) {
7
- this . top = null ;
7
+ this . top = undefined ;
8
8
}
9
9
10
10
push ( value : number ) : void {
11
11
const newNode = new ListNode ( value ) ;
12
- newNode . next = this . top !== null ? this . top : undefined ;
12
+ newNode . next = this . top ;
13
13
this . top = newNode ;
14
14
}
15
15
16
16
pop ( ) : number | undefined {
17
- if ( this . isEmpty ( ) ) {
18
- throw new Error ( 'Stack is empty' ) ;
17
+ if ( this . top === undefined ) {
18
+ return undefined ;
19
19
}
20
- const value = this . top ! . val ;
21
- this . top = this . top ! . next || null ;
22
- return value ;
20
+ const poppedNode = this . top ;
21
+ this . top = this . top . next ;
22
+ return poppedNode . val ;
23
23
}
24
24
25
25
peek ( ) : number | null {
26
- if ( this . isEmpty ( ) ) {
26
+ if ( this . top === undefined ) {
27
27
throw new Error ( 'Stack is empty' ) ;
28
28
}
29
- return this . top ! . val ;
29
+ return this . top . val ;
30
30
}
31
31
32
32
isEmpty ( ) : boolean {
33
- return this . top === null ;
33
+ return this . top === undefined ;
34
34
}
35
35
}
You can’t perform that action at this time.
0 commit comments