Skip to content

Commit

Permalink
style: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
javaswing committed Nov 20, 2023
1 parent 6eac4b6 commit b818eea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ export default class DoublyLinkedList<T> extends LinkedList<T> {
if (index >= 0 && index <= this.count) {
const node = new DoublyNode(e);
if (index == 0) {
let c = this.head;
const c = this.head;
node.next = c;
c && (c.prev = node);
this.head = node;
} else if (index === this.count - 1) {
let c = this.tail;
const c = this.tail;
node.next = c;
c && (c.prev = node);
this.tail = node;
} else {
let c = this.head;
for (let i = 0; i < this.count && c !== undefined; i++) {
if (i === index) {
let prev = c.prev;
const prev = c.prev;
prev && (prev.next = node);
node.prev = prev;
node.next = c;
Expand Down
10 changes: 7 additions & 3 deletions code/linked-list/book/doubly-linked-list/doubly-node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LinkedNode } from "../linked-node";
import { LinkedNode } from '../linked-node';

/**
* 双向链表 node 节点
Expand All @@ -7,8 +7,12 @@ export default class DoublyNode<T> extends LinkedNode<T> {
prev: DoublyNode<T> | undefined;
next: DoublyNode<T> | undefined;

constructor(element: T, next: DoublyNode<T> | undefined = undefined, prev: DoublyNode<T>| undefined = undefined) {
super(element, next)
constructor(
element: T,
next: DoublyNode<T> | undefined = undefined,
prev: DoublyNode<T> | undefined = undefined
) {
super(element, next);
this.prev = prev;
}
}

0 comments on commit b818eea

Please sign in to comment.