Update README.md
readded the insert code snippet.
This commit is contained in:
@@ -284,17 +284,13 @@ item.
|
|||||||
- If p is a pointer to this node, and x holds the value to be inserted, then the following code will do the insertion.
|
- If p is a pointer to this node, and x holds the value to be inserted, then the following code will do the insertion.
|
||||||
Draw a picture to illustrate what is happening.
|
Draw a picture to illustrate what is happening.
|
||||||
|
|
||||||
```cpp
|
|
||||||
Class exercise
|
|
||||||
```
|
|
||||||
<!--
|
|
||||||
```cpp
|
```cpp
|
||||||
Node<T> * q = new Node<T>; // create a new node
|
Node<T> * q = new Node<T>; // create a new node
|
||||||
q -> value = x; // store x in this node
|
q -> value = x; // store x in this node
|
||||||
q -> next = p -> next; // make its successor be the current successor of p
|
q -> next = p -> next; // make its successor be the current successor of p
|
||||||
p -> next = q; // make p's successor be this new node
|
p -> next = q; // make p's successor be this new node
|
||||||
```
|
```
|
||||||
-->
|
|
||||||
- Play this [animation](https://jidongxiao.github.io/CSCI1200-DataStructures/animations/lists/insert/index.html) to see how this code snippet works.
|
- Play this [animation](https://jidongxiao.github.io/CSCI1200-DataStructures/animations/lists/insert/index.html) to see how this code snippet works.
|
||||||
|
|
||||||
- Note: This code will not work if you want to insert x in a new node at the front of the linked list. Why not?
|
- Note: This code will not work if you want to insert x in a new node at the front of the linked list. Why not?
|
||||||
|
|||||||
Reference in New Issue
Block a user