Advertisement
adwas33

Untitled

Nov 8th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. void deleteFirst(node *&H)
  2. {
  3. if(H!= nullptr)
  4. {
  5. node *p=H;
  6. H=H->next;
  7. delete p;
  8. }
  9. }
  10.  
  11. void deleteSecond(node *&before)
  12. {
  13. if(before!= nullptr&&before->next!= nullptr){
  14.  
  15. node *p=before->next;
  16. before->next=before->next->next;
  17. delete p;
  18. }
  19.  
  20. }
  21.  
  22.  
  23.  
  24. void zadanie3(node *&head)
  25. {
  26. if(head!= nullptr)
  27. {
  28. node* p=head;
  29. while(p&&p->next)
  30. {
  31. if(p->value==p->next->value)
  32. {
  33. deleteSecond(p);
  34. }
  35. p=p->next;
  36. }
  37. }
  38.  
  39. }
  40.  
  41. int findMax(node *head)
  42. {
  43. int wartosc=head->value;
  44. node *p=head;
  45. while(p)
  46. {
  47. if(wartosc<p->value)
  48. {
  49. wartosc=p->value;
  50. }
  51. p=p->next;
  52. }
  53. return wartosc;
  54. }
  55.  
  56. void zadanie1(node *&head)
  57. {
  58. if(head!= nullptr)
  59. {
  60. node *p=head;
  61. int max= findMax(head);
  62. while(p->next->value!=max)
  63. {
  64. p=p->next;
  65.  
  66. }
  67. deleteSecond(p);
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement