Oh, this problem can not directly delete the known nodes. Because it is a single linked list, do not know the precursor, just know
Subsequent nodes, direct deletion causes the list to be disconnected. It's just that we can delete the subsequent nodes of the known nodes,
Assigns the value of the successor node to the known node.
#include <iostream>struct node{int data; Node* next;}; BOOL RemoveNode (node* vnode) {if (Vnode = = NULL | | vnode->next = NULL) return false; node* Pnext = Vnode->next;vnode->data = Pnext->data;vnode->next = Pnext->next;delete PNext;pNext = NULL;} void Initlist (node* vRoot) {if (VRoot = = NULL) {std::cout << "wrong node\n"; return;} for (int i=0; i<20; ++i) {node* Temp = new Node; Temp->data = i + 1; Temp->next = Vroot->next;vroot->next = Temp;}} int main () {node* Root = new Node; Root->next = null;initlist (Root), while (Root->next)//Last node did not delete {if (root) break;} Std::cout << root->data << std::endl;delete Root; Root = Null;system ("pause"); return 0;}
009 implement an algorithm to delete a node in a single-linked list, giving only pointers to that node (keep it up)