Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef struct Node
  6. {
  7. int Val;
  8. Node *ptr;
  9. } Node;
  10.  
  11. void deleteVal (int value, Node *head, Node *&prev)
  12. {
  13. Node* counter = head;
  14. while ((*counter).ptr != nullptr && (*counter).Val != value)
  15. {
  16. prev = counter;
  17. counter = (*counter).ptr;
  18. }
  19. (*prev).ptr = (*counter).ptr;
  20. }
  21.  
  22. void coutList (Node *head)
  23. {
  24. while ((*head).ptr != nullptr)
  25. {
  26. cout << (*head).Val << " ";
  27. head = (*head).ptr;
  28. }
  29. cout << (*head).Val;
  30. }
  31.  
  32. int main()
  33. {
  34. int value;
  35. Node a, b, c, d, e;
  36. Node *head, *counter, *prev;
  37.  
  38. a.Val = 1;
  39. b.Val = 2;
  40. c.Val = 3;
  41. d.Val = 4;
  42. e.Val = 5;
  43. a.ptr = &b;
  44. b.ptr = &c;
  45. c.ptr = &d;
  46. d.ptr = &e;
  47. e.ptr = nullptr;
  48. head = &a;
  49.  
  50. cin >> value;
  51. searchVal(value, head, prev);
  52. coutList(head);
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement