Advertisement
szmelu

6h na to gówno

Apr 29th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6. struct node{
  7. node * next;
  8. int value;
  9. };
  10.  
  11.  
  12. void DELL(node *& H){
  13. if(H!=NULL){
  14. node * temp=new node;
  15. temp = H;
  16. H=temp->next;
  17. delete temp;
  18. }
  19. }
  20.  
  21. void ADD( node *& H, int val){
  22. node * temp = new node;
  23. temp->next=H;
  24. temp->value=val;
  25. H=temp;
  26. }
  27.  
  28.  
  29. void show(node * H){
  30. cout <<"H->";
  31. node *temp=H;
  32. while(temp!=NULL){
  33. cout << temp->value<<"->";
  34. temp=temp->next;
  35. }
  36. cout << "NULL"<<endl;
  37. }
  38. void srednia(node*&H)
  39. {
  40. if (H != NULL)
  41. {
  42. node *temp = H;
  43. node *tmp = NULL;
  44. node *tmp2 = NULL;
  45. float x = 0, i = 0;
  46. float srednia = 0;
  47. while (temp != NULL)
  48. {
  49. if (temp->next == NULL)
  50. tmp = temp;
  51. x = x + temp->value;
  52. i++;
  53. temp = temp->next;
  54. }
  55. int z = 0;
  56. srednia = x / i;
  57. delete temp;
  58. temp = H;
  59. cout<<"srednia: " << srednia << endl;
  60. while(z < i)
  61. {
  62. z++;
  63. if(H->value > srednia)
  64. {
  65. tmp->next=temp;
  66. tmp=tmp->next;
  67. H=H->next;
  68. temp=H;
  69. }
  70. else
  71. {
  72. if(temp->value > srednia)
  73. {
  74. tmp->next=temp;
  75. tmp=tmp->next;
  76. temp=tmp2;
  77. temp->next=temp->next->next;
  78. temp=temp->next;
  79. }
  80. else
  81. {
  82. tmp2=temp;
  83. temp=temp->next;
  84. }
  85. }
  86. }
  87. tmp->next=NULL;
  88. }
  89. }
  90. int main()
  91. {
  92. node * H = NULL;
  93. ADD(H, 5);
  94. ADD(H, 4);
  95. ADD(H, 7);
  96. ADD(H,22);
  97. ADD(H,11);
  98. ADD(H,12);
  99. show(H);
  100. srednia(H);
  101. show(H);
  102.  
  103.  
  104.  
  105. system("pause");
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement