From 552a44fa94cbd2e17720757451f79078ab9f5a83 Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 12 Dec 2022 21:12:32 +0800 Subject: [PATCH] Update TypeScript style (Chapter of Array and Linkedlist) --- .../chapter_array_and_linkedlist/linked_list.ts | 4 ++++ codes/typescript/module/ListNode.ts | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/codes/typescript/chapter_array_and_linkedlist/linked_list.ts b/codes/typescript/chapter_array_and_linkedlist/linked_list.ts index d2c339df0..484322581 100644 --- a/codes/typescript/chapter_array_and_linkedlist/linked_list.ts +++ b/codes/typescript/chapter_array_and_linkedlist/linked_list.ts @@ -7,12 +7,14 @@ import ListNode from '../module/ListNode'; import { printLinkedList } from '../module/PrintUtil'; +/* 在链表的结点 n0 之后插入结点 P */ function insert(n0: ListNode, P: ListNode): void { const n1 = n0.next; n0.next = P; P.next = n1; } +/* 删除链表的结点 n0 之后的首个结点 */ function remove(n0: ListNode): void { if (!n0.next) { return; @@ -23,6 +25,7 @@ function remove(n0: ListNode): void { n0.next = n1; } +/* 访问链表中索引为 index 的结点 */ function access(head: ListNode | null, index: number): ListNode | null { for (let i = 0; i < index; i++) { if (!head) { @@ -33,6 +36,7 @@ function access(head: ListNode | null, index: number): ListNode | null { return head; } +/* 在链表中查找值为 target 的首个结点 */ function find(head: ListNode | null, target: number): number { let index = 0; while (head !== null) { diff --git a/codes/typescript/module/ListNode.ts b/codes/typescript/module/ListNode.ts index 543f1cf3a..d6d60616d 100644 --- a/codes/typescript/module/ListNode.ts +++ b/codes/typescript/module/ListNode.ts @@ -1,4 +1,12 @@ -// Definition for singly-linked list. +/* + * File: ListNode.ts + * Created Time: 2022-12-10 + * Author: Justin (xiefahit@gmail.com) + */ + +/** + * Definition for a singly-linked list node + */ export default class ListNode { val: number; next: ListNode | null;