Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef struct Node
- {
- int Val;
- Node *ptr;
- } Node;
- void deleteVal (int value, Node *head, Node *&prev)
- {
- Node* counter = head;
- while ((*counter).ptr != nullptr && (*counter).Val != value)
- {
- prev = counter;
- counter = (*counter).ptr;
- }
- (*prev).ptr = (*counter).ptr;
- }
- void coutList (Node *head)
- {
- while ((*head).ptr != nullptr)
- {
- cout << (*head).Val << " ";
- head = (*head).ptr;
- }
- cout << (*head).Val;
- }
- int main()
- {
- int value;
- Node a, b, c, d, e;
- Node *head, *counter, *prev;
- a.Val = 1;
- b.Val = 2;
- c.Val = 3;
- d.Val = 4;
- e.Val = 5;
- a.ptr = &b;
- b.ptr = &c;
- c.ptr = &d;
- d.ptr = &e;
- e.ptr = nullptr;
- head = &a;
- cin >> value;
- searchVal(value, head, prev);
- coutList(head);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement