Advertisement
Guest User

queue c++

a guest
Oct 23rd, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #define MAX 20
  4. using namespace std;
  5. struct Covek
  6. {
  7. char ime[20];
  8. char prezime[20];
  9. bool lk,p,vd;
  10. };
  11. struct Red
  12. {
  13. Covek niza[MAX];
  14. int start,end;
  15. };
  16. void inicijaliziraj(Red &r)
  17. {
  18. r.start=0;
  19. r.end=-1;
  20. }
  21. void vmetni(Red &r,Covek &c)
  22. {
  23. if(r.end==MAX-1) cout<<"greska";
  24. else
  25. {
  26. r.niza[++r.end]=c;
  27. }
  28. }
  29. Covek izvadi(Red &r)
  30. {
  31. Covek pom;
  32. if(r.end==-1) cout<<" use edna greska";
  33. else
  34. {
  35. pom=r.niza[r.start];
  36. for(int i=r.start;i<r.end;i++)
  37. {
  38. r.niza[i]=r.niza[i+1];
  39. }
  40. r.end--;
  41. }
  42. return pom;
  43. }
  44. void opsluzuva(Red &r1,Red &r2,Red &r3)
  45. {
  46. Covek c;
  47. while(r1.end>-1)
  48. {
  49. c=izvadi(r1);
  50. c.lk=false; cout<<c.ime<<" "<<c.prezime<<" licna karta"<<endl;
  51. if(c.p==true) vmetni(r2,c);
  52. else if(c.vd==true) vmetni(r3,c);
  53. }
  54. while(r2.end>-1)
  55. {
  56. c=izvadi(r2);
  57. c.p=false; cout<<c.ime<<" "<<c.prezime<<" pasos"<<endl;
  58. if(c.vd==true) vmetni(r3,c);
  59. }
  60. while(r3.end>-1)
  61. {
  62. c=izvadi(r3);
  63. c.vd=false; cout<<c.ime<<" "<<c.prezime<<" vozacka"<<endl;
  64. }
  65. }
  66. int main()
  67. {
  68. Red rlk, rp, rvd;
  69. inicijaliziraj(rlk);
  70. inicijaliziraj(rp);
  71. inicijaliziraj(rvd);
  72. Covek niza[20];
  73. bool znak;
  74. for(int i=0;i<3;i++)
  75. {
  76. cout<<"Vnesete ime:"<<endl;
  77. cin>>niza[i].ime;
  78. cout<<"Vnesete prezime"<<endl;
  79. cin>>niza[i].prezime;
  80. cout<<"Dali kje chekate vo redot za lichni karti? (1=da, 0=ne)"<<endl;
  81. cin>>niza[i].lk;
  82. cout<<"Dali kje chekate vo redot za pasoshi? (1=da, 0=ne)"<<endl;
  83. cin>>niza[i].p;
  84. cout<<"Dali kje chekate vo redot za vozachki dozvoli? (1=da, 0=ne)"<<endl;
  85. cin>>niza[i].vd;
  86. if(niza[i].lk) vmetni(rlk,niza[i]);
  87. else
  88. if(niza[i].p) vmetni(rp,niza[i]);
  89. else
  90. if(niza[i].vd) vmetni(rvd,niza[i]);
  91. /*cout<<"Ako nema povekje lugje pritisni t"<<endl;
  92. cin>>znak;
  93. if(znak=='t') break;
  94. }*/
  95. }
  96. opsluzuva(rlk,rp,rvd);
  97. return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement