forked from dennisdev/Client2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: linklist not ported properly from java
- Loading branch information
1 parent
1d6af12
commit 3791b91
Showing
14 changed files
with
105 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import DoublyLinkable from './DoublyLinkable'; | ||
|
||
export default class DoublyLinkList { | ||
readonly head: DoublyLinkable = new DoublyLinkable(); | ||
|
||
constructor() { | ||
this.head.next2 = this.head; | ||
this.head.prev2 = this.head; | ||
} | ||
|
||
push(node: DoublyLinkable): void { | ||
if (node.prev2) { | ||
node.unlink2(); | ||
} | ||
node.prev2 = this.head.prev2; | ||
node.next2 = this.head; | ||
if (node.prev2) { | ||
node.prev2.next2 = node; | ||
} | ||
node.next2.prev2 = node; | ||
} | ||
|
||
pop(): DoublyLinkable | null { | ||
const node: DoublyLinkable | null = this.head.next2; | ||
if (node === this.head) { | ||
return null; | ||
} else { | ||
node?.unlink2(); | ||
return node; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Linkable from './Linkable'; | ||
|
||
export default class DoublyLinkable extends Linkable { | ||
// constructor | ||
next2: DoublyLinkable | null = null; | ||
prev2: DoublyLinkable | null = null; | ||
|
||
unlink2(): void { | ||
if (this.prev2 !== null) { | ||
this.prev2.next2 = this.next2; | ||
if (this.next2) { | ||
this.next2.prev2 = this.prev2; | ||
} | ||
this.next2 = null; | ||
this.prev2 = null; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,16 @@ | ||
export default class Linkable { | ||
key: bigint; | ||
next: Linkable | null; | ||
prev: Linkable | null; | ||
|
||
constructor() { | ||
this.key = 0n; | ||
this.next = this; | ||
this.prev = this; | ||
} | ||
key: bigint = 0n; | ||
next: Linkable | null = null; | ||
prev: Linkable | null = null; | ||
|
||
unlink(): void { | ||
if (!this.prev || !this.next) { | ||
return; | ||
if (this.prev != null) { | ||
this.prev.next = this.next; | ||
if (this.next) { | ||
this.next.prev = this.prev; | ||
} | ||
this.next = null; | ||
this.prev = null; | ||
} | ||
this.prev.next = this.next; | ||
this.next.prev = this.prev; | ||
this.next = null; | ||
this.prev = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters