Posted By


bagrancar on 12/03/11

Tagged


Statistics


Viewed 205 times
Favorited by 0 user(s)

Struktrure_podataka_glavni_program


/ Published in: C++
Save to your folder(s)

Strukture podataka glavni program.


Copy this code and paste it in your HTML
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <ctime>
  4. #include "biblioteka_pokazivac.h"
  5. #include "biblioteka_vrijeme.h"
  6. //#include "biblioteka_polje.h"
  7.  
  8. using namespace std;
  9.  
  10. int n;
  11.  
  12. void generiranje(r *musterije){
  13. srand(time(0));
  14. cout<<"Unesite zeljeni broj parova za generiranje? (1-10000)"<<endl;
  15. cin>>n;
  16. tpopis novi;
  17. for(int i=0;i<n;i++){
  18. novi.rb=i+1;
  19. novi.x=((rand()%10001)/1000)+1;
  20. novi.y=((rand()%10001)/1000)+1;
  21. novi.p=(rand()%4)+1;
  22. enqueueq(novi,musterije);
  23. }
  24. };
  25. void ispis(r *musterije){
  26. vrijeme_pocetak();
  27. cout<<"musterije"<<endl;
  28. cout<<"-----------------------------------"<<endl;
  29. tpopis tekuci;
  30. if(isemptyq(musterije)) cout<<"Red je prazan!"<<endl;
  31. while(!isemptyq(musterije)){
  32. tekuci=frontq(musterije);
  33. dequeueq(musterije);
  34. cout<<"musterija broj: "<<tekuci.rb<<endl;
  35. cout<<"Cekati cete "<<tekuci.x<<" minuta."<<endl;
  36. cout<<"U ordinaciji ste "<<tekuci.y<<" minuta."<<endl;
  37. cout<<"Prednost ima: "<<tekuci.p<<endl;
  38. cout<<"-----------------------------------"<<endl;
  39. }
  40. vrijeme_kraj();
  41. cout<<"Vrijeme izvodjenja: "<<vrijeme_proteklo()/1000<<endl;
  42. };
  43.  
  44. void nula(tpopis *polje){
  45. for(int i=0;i<n;i++){
  46. polje[i].rb=0;
  47. polje[i].x=0;
  48. polje[i].y=0;
  49. polje[i].p=0;
  50. }
  51. n=0;
  52. }
  53. void promjena(r *musterije){
  54. vrijeme_pocetak();
  55. tpopis ordinacija[10000];
  56. int brojac=0;
  57. while(!isemptyq(musterije)){
  58. ordinacija[brojac]=frontq(musterije);
  59. brojac++;
  60. dequeueq(musterije);}
  61.  
  62. //sortiranje bubble sort
  63. bool zamjena=true;
  64. for(int i=n-1;i>0&&zamjena; i--){
  65. zamjena=false;
  66. for(int j=0;j<i;j++){
  67. if(ordinacija[j].p<ordinacija[j+1].p){
  68. tpopis pom=ordinacija[j];
  69. ordinacija[j]=ordinacija[j+1];
  70. ordinacija[j+1]=pom;
  71. zamjena=true;
  72. }
  73. if(ordinacija[j].p==ordinacija[j+1].p){
  74. if(ordinacija[j].x<ordinacija[j+1].x){
  75. tpopis pom=ordinacija[j];
  76. ordinacija[j]=ordinacija[j+1];
  77. ordinacija[j+1]=pom;
  78. zamjena=true;
  79. }
  80. }
  81. }
  82. }
  83.  
  84. for(int i=0;i<n;i++) enqueueq(ordinacija[i],musterije);
  85.  
  86. cout<<"musterije:"<<endl;
  87. cout<<"-----------------------------------"<<endl;
  88. tpopis tekuci;
  89. if(isemptyq(musterije)) cout<<"Red je prazan!"<<endl;
  90. while(!isemptyq(musterije)){
  91. tekuci=frontq(musterije);
  92. dequeueq(musterije);
  93. cout<<"musterija broj: "<<tekuci.rb<<endl;
  94. cout<<"vrijeme cekanja je "<<tekuci.x<<" minuta."<<endl;
  95. cout<<"U ordinaciji ste "<<tekuci.y<<" minuta."<<endl;
  96. cout<<"Prednost je dodjeljena: "<<tekuci.p<<endl;
  97. cout<<"-----------------------------------"<<endl;
  98. }
  99. vrijeme_kraj();
  100. cout<<"Vrijeme proteklo: "<<vrijeme_proteklo()/1000<<endl;
  101. nula(ordinacija);
  102. }
  103.  
  104. int main(int argc, char *argv[])
  105. {
  106. int izbor;
  107. r *musterije;
  108. musterije=new r;
  109. initq(musterije);
  110. do{
  111. cout<<"1. Generiranje musterija"<<endl;
  112. cout<<"2. Simulacija"<<endl;
  113. cout<<"3. promjena"<<endl;
  114. cout<<"4. Kraj programa"<<endl;
  115. cin>>izbor;
  116. switch(izbor){
  117. case 1: generiranje(musterije); break;
  118. case 2: ispis(musterije);break;
  119. case 3: promjena(musterije);break;
  120. case 4: return 0;
  121. default: break;
  122. }}
  123. while(1);
  124. system("pause");
  125. return 0;
  126. }

URL: www.snipplr.com/strukture_glavni

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.