Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2b6ad98

Browse files
committed
单向链表封装的代码修改
1 parent 3b0865e commit 2b6ad98

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

‎src/LinkedList/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LinkedList } from './linkedList';
22

3-
// ----- 单向链表结构测试 -----//
3+
// ---------------- 封装的单向链表结构测试 ---------------- //
44
console.log('// ----- 单向链表结构测试 START -----//');
55
const linkedList = new LinkedList();
66

‎src/LinkedList/linkedList.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class LinkedList {
1919

2020
// ------------ 链表的常见操作 ------------ //
2121

22-
// append() 往链表尾部追加数据
22+
// append(data) 往链表尾部追加数据
2323
append(data) {
2424
// 1、创建新节点
2525
const newNode = new Node(data);
@@ -46,7 +46,7 @@ export class LinkedList {
4646
this.length++;
4747
}
4848

49-
// insert() 在指定位置(position)插入节点
49+
// insert(position, data) 在指定位置(position)插入节点
5050
insert(position, data) {
5151
// position 新插入节点的位置
5252
// position = 0 表示新插入后是第一个节点
@@ -91,7 +91,7 @@ export class LinkedList {
9191
return newNode;
9292
}
9393

94-
// getData() 获取指定位置的 data
94+
// getData(position) 获取指定位置的 data
9595
getData(position) {
9696
// 1、position 越界判断
9797
if (position < 0 || position >= this.length) return null;
@@ -108,7 +108,7 @@ export class LinkedList {
108108
return currentNode.data;
109109
}
110110

111-
// indexOf() 返回指定 data 的 index,如果没有,返回 -1。
111+
// indexOf(data) 返回指定 data 的 index,如果没有,返回 -1。
112112
indexOf(data) {
113113
let currentNode = this.head;
114114
let index = 0;
@@ -124,7 +124,7 @@ export class LinkedList {
124124
return -1;
125125
}
126126

127-
// update() 修改指定位置节点的 data
127+
// update(position, data) 修改指定位置节点的 data
128128
update(position, data) {
129129
// 涉及到 position 都要进行越界判断
130130
// 1、position 越界判断
@@ -143,7 +143,7 @@ export class LinkedList {
143143
return currentNode;
144144
}
145145

146-
// removeAt() 删除指定位置的节点
146+
// removeAt(position) 删除指定位置的节点,并返回删除的那个节点
147147
removeAt(position) {
148148
// 1、position 越界判断
149149
if (position < 0 || position >= this.length) return null;
@@ -175,9 +175,9 @@ export class LinkedList {
175175
return currentNode;
176176
}
177177

178-
// remove() 删除指定 data 的节点
178+
// remove(data) 删除指定 data 的节点,并返回删除的那个节点
179179
remove(data) {
180-
this.removeAt(this.indexOf(data));
180+
returnthis.removeAt(this.indexOf(data));
181181
}
182182

183183
// isEmpty() 判断链表是否为空

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /