Skip to content

Commit 6086a40

Browse files
authored
Merge pull request #4 from ETH-PEACH-Lab/update-insertNode-and-remove-insertEdge-(deprecated)
fix: update insertNode method signature and documentation for clarity
2 parents beaf61a + 3625963 commit 6086a40

2 files changed

Lines changed: 15 additions & 22 deletions

File tree

docs/data-structures/linkedlist.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,14 @@ LinkedLists support these methods for manipulation:
4747

4848
### Node Methods
4949
- `addNode(name, value?)` - Add new node with optional value
50-
- `insertNode(index, name)` - Insert node at specific position
50+
- `insertNode(index | id, name, value?)` - Insert node at specific position or after node ID with optional value
5151
- `removeNode(name)` - Remove specific node
5252
- `setValue(index | id, value)` - Set value for node at index or node id
5353
- `setColor(index | id, color)` - Set color for node at index or node id
5454
- `setArrow(index | id, arrow)` - Set arrow for node at index or node id
5555

5656
### Value Methods
5757
- `addValue(value)` - Add value to end of list
58-
- `insertValue(index | id, value)` - Insert value at specific position or node id
5958
- `removeValue(value)` - Remove first occurrence of value
6059
- `removeAt(index)` - Remove node at specific position
6160

@@ -124,11 +123,15 @@ list.setColor(2, "green")
124123
list.setArrow(2, "new")
125124

126125
page
127-
list.insertNode(1, n1_5)
128-
list.setValues([10, 15, 20, 30])
126+
list.insertNode(1, n1_5, 15) // insert by index
129127
list.setColors([null, "blue", null, "green"])
130128
list.setArrows([null, "inserted", null, null])
131129

130+
page
131+
list.insertNode(n1_5, n1_75, 17.5) // insert after node ID
132+
list.setColors([null, "blue", "yellow", null, "green"])
133+
list.setArrows([null, "inserted", "after n1_5", null, null])
134+
132135
page
133136
list.removeNode(n2)
134137
list.setValues([10, 15, 30])
@@ -195,8 +198,7 @@ page
195198
show sorted
196199

197200
page
198-
sorted.insertNode(1, n25)
199-
sorted.setValues([10, 25, 30, 50])
201+
sorted.insertNode(n10, n25, 25) // insert after n10 node
200202
sorted.setColor(1, "red")
201203
sorted.setArrow(1, "inserted")
202204
`}

docs/methods.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ Inserts a value at a specific index.
293293
obj.insertValue(1, "inserted")
294294
```
295295

296-
**Supported by:** Array, Stack, LinkedList
296+
**Supported by:** Array, Stack
297297

298298
---
299299

@@ -310,12 +310,15 @@ graph.addNode(newNode) // no value
310310

311311
---
312312

313-
### `insertNode(index, name)`
314-
Inserts a node at a specific index.
313+
### `insertNode(index | id, name, value?)`
314+
Inserts a node at a specific index or after a specific node ID with optional value.
315315

316316
**Syntax:**
317317
```merlin
318-
list.insertNode(1, newNode)
318+
list.insertNode(1, newNode) // by index
319+
list.insertNode(1, newNode, "value") // by index with value
320+
list.insertNode(nodeA, newNode) // after node ID
321+
list.insertNode(nodeA, newNode, "value") // after node ID with value
319322
```
320323

321324
**Supported by:** LinkedList
@@ -334,18 +337,6 @@ graph.addEdge(nodeA-nodeB)
334337

335338
---
336339

337-
### `insertEdge(index, edge)`
338-
Inserts an edge at a specific index.
339-
340-
**Syntax:**
341-
```merlin
342-
graph.insertEdge(1, nodeA-nodeB)
343-
```
344-
345-
**Supported by:** Graph
346-
347-
---
348-
349340
### `setEdges([...])`
350341
Sets all edges at once.
351342

0 commit comments

Comments
 (0)