Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. // Hitro_Uredi.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include<iostream>
  6. #include <cstdlib>
  7. #include <ctime>
  8. #include <time.h>
  9. using namespace std;
  10.  
  11. int a[1000000], dolzinaZaporedja;
  12.  
  13. void generirajNakljucno();
  14. void generirajNarascajoce();
  15. void generirajPadajoce();
  16. void izpisZaporedja();
  17. int DELI(int dno, int vrh);
  18. void HITRO_UREDI(int dno, int vrh);
  19. void PREVERI(int dno, int vrh);
  20. int _tmain(int argc, _TCHAR* argv[])
  21. {
  22. int meni = 0;
  23. clock_t start, finish;
  24. double duration;
  25.  
  26.  
  27. while(meni != 6){
  28. cout << endl << "Hitro uredi - izbira:" << endl << endl;
  29. cout << "1 Generiraj naključno zaporedje" << endl;
  30. cout << "2 Generiraj urejeno naraščajoče zaporedje" << endl;
  31. cout << "3 Generiraj urejeno padajoče zaporedje" << endl;
  32. cout << "4 Izpis zaporedja" << endl;
  33. cout << "5 Uredi" << endl;
  34. cout << "6 Konec" << endl << endl;
  35. cout << "Vaša izbira: ";
  36.  
  37. cin >> meni;
  38.  
  39. if(meni > 0 && meni < 4){
  40. cout << endl << "Vpisi dolzino zaporedja: ";
  41. cin >> dolzinaZaporedja;
  42. }
  43.  
  44. if(meni == 1)
  45. generirajNakljucno();
  46.  
  47. else if(meni == 2)
  48. generirajNarascajoce();
  49.  
  50. else if(meni == 3)
  51. generirajPadajoce();
  52.  
  53. else if(meni == 4)
  54. izpisZaporedja();
  55.  
  56. else if(meni == 5){
  57. int dno = 0, vrh = dolzinaZaporedja - 1;
  58. start = clock();
  59. HITRO_UREDI(dno, vrh);
  60. finish = clock();
  61. PREVERI( dno, vrh);
  62. duration = (double)(finish - start);
  63. cout << endl << "Cas urejanja: "<< duration << " sec" << endl;
  64. }
  65.  
  66. }
  67. return 0;
  68. }
  69.  
  70. int DELI(int dno, int vrh){
  71. int l = dno, d = vrh, m = (dno+vrh)/2, temp;
  72. temp = a [dno];
  73. a[dno] = a[m];
  74. a[m] = temp;
  75. while(l < d)
  76. {
  77. while(a[l] <= a[dno] && l < vrh)
  78. {
  79. l++;
  80. }
  81. while(a[d] >= a[dno] && d > dno)
  82. {
  83. d--;
  84. }
  85. if(l < d)
  86. {
  87. temp = a[l];
  88. a[l] = a[d];
  89. a[d] = temp;
  90. }
  91. }
  92. temp = a[dno];
  93. a[dno] = a[d];
  94. a[d] = temp;
  95. return d;
  96. }
  97. void PREVERI(int dno, int vrh)
  98. {
  99. for(int i=dno;i<vrh-1;i++)
  100. {
  101. if(a[i+1] < a[i])
  102. {
  103. cout<<"Napacno zaporedje: "<<a[i+1]<<" "<<a[i];
  104. }
  105. }
  106. }
  107. void HITRO_UREDI(int dno, int vrh)
  108. {
  109. int j;
  110. if(dno<vrh)
  111. {
  112. j=DELI(dno,vrh);
  113. HITRO_UREDI(dno,j-1);
  114. HITRO_UREDI(j+1,vrh);
  115. }
  116. }
  117. void izpisZaporedja()
  118. {
  119. cout<<endl<<"Zaporedje: ";
  120. for(int i=0;i<dolzinaZaporedja;i++)
  121. {
  122. cout<<a[i]<<" ";
  123. }
  124. cout<<endl;
  125. }
  126. void generirajNakljucno()
  127. {
  128. srand((unsigned)time(0));
  129. int random_integer;
  130. for(int i = 0; i <= dolzinaZaporedja; i++)
  131. {
  132. random_integer = rand() % 10;
  133. a[i] = random_integer;
  134. }
  135. }
  136. void generirajNarascajoce()
  137. {
  138. for(int i = 0; i < dolzinaZaporedja; i++)
  139. {
  140. a[i] = i;
  141. }
  142. }
  143. void generirajPadajoce()
  144. {
  145. int x = dolzinaZaporedja - 1;
  146. for(int i = 0; i < dolzinaZaporedja; i++)
  147. {
  148. a[i] = x;
  149. x--;
  150. }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement