Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. //Sortare descrescatoare.
  2.  
  3. #include<iostream>
  4. #include<limits.h>
  5.  
  6. using namespace std;
  7. int V[100];
  8. int n;
  9. int main()
  10. {
  11. cout<<"n=";cin>>n;
  12. for(int i=1;i<=n;i++)
  13. { cout<<"V["<<i<<"]=";
  14. cin>>V[i];
  15. }
  16. for(int i=1;i<=n-1;i++)
  17. {
  18. int minim=INT_MIN;
  19. int locul=0;
  20. for(int j=i;j<=n;j++)
  21. {
  22. if (minim<V[j]) {
  23. minim=V[j];
  24. locul=j;
  25. }
  26. }
  27. swap(V[i],V[locul]);
  28. }
  29. cout<<endl<<"Sortate "<<endl;
  30. for(int i=1;i<=n;i++)
  31. cout<<V[i]<<" ";
  32. }
  33.  
  34. //Locatie de index 0.
  35.  
  36. #include<iostream>
  37. #include<limits.h>
  38.  
  39. using namespace std;
  40. int V[100];
  41. int n;
  42. int main()
  43. {
  44. cout<<"n=";cin>>n;
  45. for(int i=0;i<=n-1;i++)
  46. { cout<<"V["<<i<<"]=";
  47. cin>>V[i];
  48. }
  49. for(int i=0;i<=n-1;i++)
  50. {
  51. int minim=INT_MAX;
  52. int locul=0;
  53. for(int j=i;j<=n-1;j++)
  54. {
  55. if (minim>V[j]) {
  56. minim=V[j];
  57. locul=j;
  58. }
  59. }
  60. swap(V[i],V[locul]);
  61. }
  62. cout<<endl<<"Sortate "<<endl;
  63. for(int i=0;i<=n-1;i++)
  64. cout<<V[i]<<" ";
  65. }
  66.  
  67. //Initializarea minimului cu primul.
  68.  
  69. #include<iostream>
  70. #include<limits.h>
  71.  
  72. using namespace std;
  73. int V[100];
  74. int n;
  75. int main()
  76. {
  77. cout<<"n=";cin>>n;
  78. for(int i=1;i<=n;i++)
  79. { cout<<"V["<<i<<"]=";
  80. cin>>V[i];
  81. }
  82. for(int i=1;i<=n-1;i++)
  83. {
  84. int primul=INT_MAX;
  85. int locul=0;
  86. for(int j=i;j<=n;j++)
  87. {
  88. if (V[j]<primul) {
  89. primul=V[j];
  90. locul=j;
  91. }
  92. }
  93. swap(V[i],V[locul]);
  94. }
  95. cout<<endl<<"Sortate "<<endl;
  96. for(int i=1;i<=n;i++)
  97. cout<<V[i]<<" ";
  98. }
  99.  
  100. //Parcurgerea NS de la coada spre inceput.
  101.  
  102. #include<iostream>
  103. #include<limits.h>
  104.  
  105. using namespace std;
  106. int V[100];
  107. int n;
  108. int main()
  109. {
  110. cout<<"n=";cin>>n;
  111. for(int i=1;i>0;i--)
  112. { cout<<"V["<<i<<"]=";
  113. cin>>V[i];
  114. }
  115. for(int i=1;i>0;i--)
  116. {
  117. int minim=INT_MAX;
  118. int locul=0;
  119. for(int j=i;j>0;j--)
  120. {
  121. if (V[j]=minim) {
  122. minim=V[j];
  123. locul=j;
  124. }
  125. }
  126. swap(V[i],V[locul]);
  127. }
  128. cout<<endl<<"Sortate "<<endl;
  129. for(int i=1;i>0;i--)
  130. cout<<V[i]<<" ";
  131. return 1;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement