Commit d0d22181 authored by h702579998's avatar h702579998

All done with deleting node at an index, have not tested it for when you try to…

All done with  deleting node at an index, have not tested it for when you try to delete INDEX 0 though.
parent 1733463e
...@@ -114,8 +114,10 @@ NODE_INT traverseBefore(NODE *head, int pos, int offset){ ...@@ -114,8 +114,10 @@ NODE_INT traverseBefore(NODE *head, int pos, int offset){
int delete_node_at(NODE *head, int pos){ int delete_node_at(NODE *head, int pos){
NODE_INT nodeToDelete = traverse(head, pos); NODE_INT nodeToDelete = traverse(head, pos);
NODE_INT priorNode = traverse(head, pos-1); NODE_INT priorNode = traverse(head, pos-1);
priorNode.node->next = nodeToDelete.node->next;
//NODE *nextNode = nodeToDelete.node->next;
free(nodeToDelete.node);
return 0;
} }
......
...@@ -21,7 +21,10 @@ int menu(struct Node *head){ ...@@ -21,7 +21,10 @@ int menu(struct Node *head){
add_to_end(head, value); add_to_end(head, value);
break; break;
case 2: //delete node at case 2: //delete node at
// break; fputs("You have decided to delete a node. Input it: \n",stdout);
scanf("%d",&index);
delete_node_at(head, index);
break;
case 3: //insert case 3: //insert
fputs("You have decided to insert a value at a specific point. Input the node index now: ",stdout); fputs("You have decided to insert a value at a specific point. Input the node index now: ",stdout);
scanf("%d",&index); scanf("%d",&index);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment