#include #include using namespace std; struct Node { int data; Node *next; }; void printNodes(Node *n) { while (n != NULL) { cout << n->data << endl; n = n->next; } } void deleteNode(Node *n, int d) { Node *before; while (n != NULL) { if (n->data == d) { before->next = n->next; delete n; } before = n; n = n->next; } } // add a node to the end of the list void addNode(Node *n, int i) { Node *prev; while (n != NULL) { prev = n; n = n->next; } n = new Node; prev->next = n; n->data = i; n->next = NULL; } int main() { Node *Head = new Node; Head->data = 0; Head->next = NULL; for(int x=0; x<10; x++) { addNode(Head, x); } printNodes(Head); deleteNode(Head, 5); printNodes(Head); return 0; }