Guest User

Untitled

a guest
Jan 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. typedef float Tdata;
  2.  
  3. struct Tnode
  4. {
  5. Tdata info;
  6. Tnode *next;
  7. };
  8.  
  9. typedef Tnode* Tlist;
  10. Tlist L=0;
  11.  
  12. void output(Tlist L);
  13. void create_L(Tlist &L, int n);
  14. Tlist min(Tlist L);
  15. Tlist max(Tlist L);
  16. void change(Tlist &L);
  17. //
  18.  
  19. int main ()
  20. {
  21. setlocale(0,"Rus");
  22. int n;
  23. cout<<"vvedite kolichestvo uzlov ";
  24. cin>>n;
  25. create_L(L,n);
  26. cout<<"vvedinnye chisla: ";
  27. output(L);
  28.  
  29.  
  30.  
  31. change(L);
  32. cout<<"chisla posle sortirovki: ";
  33. output(L);
  34.  
  35. _getch();
  36. return 0;
  37. }
  38.  
  39. void output(Tlist L)
  40. {
  41. Tlist q=L;
  42. while (q)
  43. {
  44. cout<<(q->info)<<" ";
  45. q=q->next;
  46. }
  47. cout<<endl;
  48. }
  49.  
  50.  
  51. void create_L(Tlist &L, int n)
  52. {
  53. L=new Tnode;
  54. cout<<"vvedite chislo ";
  55. cin>>(L->info);
  56. L->next=0;
  57. Tnode *q1, *q2;
  58. q1=L;
  59. for(int i=1; i<n; i++)
  60. {
  61. q2 = new Tnode;
  62. cout<<"vvedite chislo ";
  63. cin>>(q2->info);
  64. q2->next=0;
  65. q1->next=q2;
  66. q1=q2;
  67. }
  68. }
  69.  
  70. Tlist min(Tlist L)
  71. {
  72. Tlist q=L;
  73. Tlist q_min;
  74. q_min=q;
  75. q=q->next;
  76. while (q)
  77. {
  78. if ((q_min->info)>(q->info))
  79. q_min=q;
  80. q=q->next;
  81. }
  82. return q_min;
  83. }
  84.  
  85. Tlist max(Tlist L)
  86. {
  87. Tlist q=L;
  88. Tlist q_max;
  89. q_max=q;
  90. q=q->next;
  91. while (q)
  92. {
  93. if ((q_max->info)<(q->info))
  94. q_max=q;
  95. q=q->next;
  96. }
  97. return q_max;
  98. }
  99.  
  100. void change(Tlist &L)
  101. {
  102. Tlist q=L;
  103. float temp1;
  104. float L_min=min(L)->info;
  105. float L_max=max(L)->info;
  106. while (q)
  107. {
  108. if ((q->info)==(L_min))
  109. q->info=L_max;
  110. else
  111. if ((q->info)==(L_max))
  112. q->info=L_min;
  113. q=q->next;
  114. }
  115. }
Add Comment
Please, Sign In to add comment