File tree Expand file tree Collapse file tree 6 files changed +62
-62
lines changed
Expand file tree Collapse file tree 6 files changed +62
-62
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ export class LinkedListNode<T> {
1111}
1212
1313
14- export class LinkedList < T > {
14+ export class DoublyLinkedList < T > {
1515 head : LinkedListNode < T > | null ;
1616 tail : LinkedListNode < T > | null ;
1717 current : LinkedListNode < T > | null ;
Original file line number Diff line number Diff line change 4040
4141<script setup lang="ts">
4242import { ref , onMounted } from ' vue' ;
43- import { LinkedListNode , LinkedList } from ' ../LinkedList .ts' ;
43+ import { LinkedListNode , DoublyLinkedList } from ' ./DoublyLinkedList .ts' ;
4444
4545const audioPlayer = ref <HTMLAudioElement | null >(null );
46- const playlist = ref (new LinkedList <{title: string , src: string }>());
46+ const playlist = ref (new DoublyLinkedList <{title: string , src: string }>());
4747const currentSong = ref <LinkedListNode <{title: string , src: string }> | null >(null );
4848const isPlaying = ref (false );
4949const progress = ref (0 );
Original file line number Diff line number Diff line change 1+ class Node < T > {
2+ data : T ;
3+ next : Node < T > | null = null ;
4+ prev : Node < T > | null = null ;
5+
6+ constructor ( data : T ) {
7+ this . data = data ;
8+ }
9+ }
10+
11+ export class LinkedList < T > {
12+ private head : Node < T > | null = null ;
13+ private current : Node < T > | null = null ;
14+
15+ add ( data : T ) : void {
16+ const newNode = new Node ( data ) ;
17+
18+ if ( ! this . head ) {
19+ this . head = newNode ;
20+ this . current = this . head ;
21+ } else if ( this . current ) {
22+ this . current . next = newNode ;
23+ newNode . prev = this . current ;
24+ this . current = newNode ;
25+ }
26+ }
27+
28+ undo ( ) : T | null {
29+ if ( this . current && this . current . prev ) {
30+ this . current = this . current . prev ;
31+ return this . current . data ;
32+ }
33+ return null ;
34+ }
35+
36+ redo ( ) : T | null {
37+ if ( this . current && this . current . next ) {
38+ this . current = this . current . next ;
39+ return this . current . data ;
40+ }
41+ return null ;
42+ }
43+
44+ canUndo ( ) : boolean {
45+ return ! ! this . current && ! ! this . current . prev ;
46+ }
47+
48+ canRedo ( ) : boolean {
49+ return ! ! this . current && ! ! this . current . next ;
50+ }
51+
52+ getCurrentData ( ) : T | null {
53+ return this . current ? this . current . data : null ;
54+ }
55+ }
Original file line number Diff line number Diff line change 1111
1212<script setup lang="ts">
1313import { ref , onMounted } from ' vue' ;
14-
15- class Node <T > {
16- data: T ;
17- next: Node <T > | null = null ;
18- prev: Node <T > | null = null ;
19-
20- constructor (data : T ) {
21- this .data = data ;
22- }
23- }
24-
25- class LinkedList <T > {
26- private head: Node <T > | null = null ;
27- private current: Node <T > | null = null ;
28-
29- add(data : T ): void {
30- const newNode = new Node (data );
31-
32- if (! this .head ) {
33- this .head = newNode ;
34- this .current = this .head ;
35- } else if (this .current ) {
36- this .current .next = newNode ;
37- newNode .prev = this .current ;
38- this .current = newNode ;
39- }
40- }
41-
42- undo(): T | null {
43- if (this .current && this .current .prev ) {
44- this .current = this .current .prev ;
45- return this .current .data ;
46- }
47- return null ;
48- }
49-
50- redo(): T | null {
51- if (this .current && this .current .next ) {
52- this .current = this .current .next ;
53- return this .current .data ;
54- }
55- return null ;
56- }
57-
58- canUndo(): boolean {
59- return !! this .current && !! this .current .prev ;
60- }
61-
62- canRedo(): boolean {
63- return !! this .current && !! this .current .next ;
64- }
65-
66- getCurrentData(): T | null {
67- return this .current ? this .current .data : null ;
68- }
69- }
14+ import { LinkedList } from ' @/structures/list/examples/paint/LinkedList.ts'
7015
7116const canvas = ref <HTMLCanvasElement | null >(null );
7217let ctx: CanvasRenderingContext2D | null = null ;
Original file line number Diff line number Diff line change 11<script setup lang="ts">
22import AppSection from ' @/components/section/app-section.vue'
3- import MusicPlayer from ' @/structures/list/examples/music-player.vue'
4- import Paint from ' @/structures/list/examples/paint.vue'
3+ import MusicPlayer from ' @/structures/list/examples/music-player/music-player .vue'
4+ import Paint from ' @/structures/list/examples/paint/paint .vue'
55 </script >
66
77<template >
Original file line number Diff line number Diff line change 11<script setup lang="ts">
22import AppSection from ' @/components/section/app-section.vue'
33import Tags from ' @/structures/set/examples/tags.vue'
4- import MusicPlayer from ' @/structures/list/examples/music-player.vue'
4+ import MusicPlayer from ' @/structures/list/examples/music-player/music-player .vue'
55 </script >
66
77<template >
You can’t perform that action at this time.
0 commit comments