From 95e4e5d713d60e1f5532e8ceaf002d0c9f72036d Mon Sep 17 00:00:00 2001 From: YuJian Date: Wed, 11 May 2022 16:20:16 +0800 Subject: [PATCH] vault backup: 2022-05-11 16:20:16 --- .../数据结构 - 链表.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/数据结构与算法之美/数据结构 - 链表.md b/数据结构与算法之美/数据结构 - 链表.md index 0292e24..5d53b31 100644 --- a/数据结构与算法之美/数据结构 - 链表.md +++ b/数据结构与算法之美/数据结构 - 链表.md @@ -1,5 +1,29 @@ ## 数组转换成链表 +```typescript +interface LinkedList { + value: Number | null; + next: LinkedList | null; +} + +const toLinkedList = (array: Number[]): LinkedList => { + let linkedList: LinkedList = { + value: null, + next: null, + }; + + const endLength = array.length - 1; + for (let index = endLength; index >= 0; index--) { + linkedList = { + value: array[index], + next: index === endLength ? null : linkedList, + }; + } + + return linkedList; +}; +``` + ## 反转单向链表 ## 使用链表实现队列 \ No newline at end of file