Created
June 7, 2018 10:14
-
-
Save iamvon/ec0d47ae8bdc5464f93fb402fc5dbd97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Node* addNode(Node* head, int index, int value){ | |
| Node *addElement = new Node; | |
| Node *pre = new Node; | |
| Node *cur = new Node; | |
| addElement->value = value; | |
| addElement->nextNode = NULL; | |
| if(head == NULL) head = addElement; | |
| else { | |
| cur = head; | |
| for(int i = 0; i <= index; ++i) { | |
| pre = cur; | |
| cur = cur->nextNode; | |
| } | |
| pre->nextNode = addElement; | |
| addElement->nextNode = cur; | |
| } | |
| return head; | |
| } | |
| Node* deleteNode(Node* head, int index){ | |
| Node *pre = new Node; | |
| Node *cur = new Node; | |
| cur = head; | |
| if(head == NULL) return head; | |
| else { | |
| for(int i = 0; i < index; ++i) { | |
| pre = cur; | |
| cur = cur->nextNode; | |
| } | |
| pre->nextNode = cur->nextNode; | |
| return head; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment