Skip to content

Commit 744865a

Browse files
committed
добавление граф редактора
1 parent 27b9464 commit 744865a

File tree

6 files changed

+62
-62
lines changed

6 files changed

+62
-62
lines changed

src/structures/list/LinkedList.ts renamed to src/structures/list/examples/music-player/DoublyLinkedList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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;

src/structures/list/examples/music-player.vue renamed to src/structures/list/examples/music-player/music-player.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040

4141
<script setup lang="ts">
4242
import { ref, onMounted } from 'vue';
43-
import { LinkedListNode, LinkedList } from '../LinkedList.ts';
43+
import { LinkedListNode, DoublyLinkedList } from './DoublyLinkedList.ts';
4444
4545
const 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}>());
4747
const currentSong = ref<LinkedListNode<{title: string, src: string}> | null>(null);
4848
const isPlaying = ref(false);
4949
const progress = ref(0);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
}

src/structures/list/examples/paint.vue renamed to src/structures/list/examples/paint/paint.vue

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,62 +11,7 @@
1111

1212
<script setup lang="ts">
1313
import { 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
7116
const canvas = ref<HTMLCanvasElement | null>(null);
7217
let ctx: CanvasRenderingContext2D | null = null;

src/structures/list/view-list.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import 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>

src/structures/set/view-set.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import AppSection from '@/components/section/app-section.vue'
33
import 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>

0 commit comments

Comments
 (0)