Advertisement
NAEGAKURE

red

Jun 6th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4.  
  5. struct node
  6. {
  7.     node *link;
  8.     int data;
  9. };
  10.  
  11. //DEKLARACIJE FUNKCIJA
  12. bool queueEmpty(node *head); //funkcija koja vraca true ako je red prazan, false ako nije prazan
  13. void entry(node *&head, node *&tail, int elt); //funkcija koja dodaje element u red
  14. int process(node *&head,node *&tail); //funkcija koja vraca podatak koji se nalazi na poèetku reda i ujedno brise taj podatak iz reda
  15. void deleteQueue(node *&head,node *&tail); //funkcija koja brise cijeli red = dealokacija
  16. int waitingNum(node *head); //funkcija koja vraca broj ljudi u redu
  17.  
  18. int main()
  19. {
  20.     node *head=NULL, *tail=NULL;
  21.     int elt=1;
  22.     char odabir;
  23.     do
  24.     {
  25.         //system("cls");
  26.         cout<<"\n\nBANKA d.d. Glavni izbornik...I-Z-B-O-R-N-I-K"<<endl;
  27.         cout<<"\n1 - Ulaz nove stranke";
  28.         cout<<"\n2 - Obrada stranke";
  29.         cout<<"\n3 - Ispis trenutnog stanja";
  30.         cout<<"\n0 - Kraj";
  31.         cout<<"\n\nUnesite Vas odabir...";
  32.         cin>>odabir;
  33.         cin.ignore(1,'\n');
  34.         switch(odabir)
  35.         {
  36.         case '1':
  37.             cout<<"Klikom na gumb preuzmite listic s brojem cekanja u redu.\n";
  38.             entry(head,tail,elt);
  39.             elt++;
  40.             break;
  41.         case '2':
  42.             if(!queueEmpty(head)) cout<<"Salter je slobodan. Molimo stranku s rednim brojem: "<<process(head,tail)<<" da dodje na salter"<<endl;
  43.             else cout<<"Red je prazan, nema kandidata za nove transkacije."<<endl;
  44.             break;
  45.         case '3':
  46.             cout<<"U redu na salteru ceka "<<waitingNum(head)<<" ljudi.\n";
  47.             break;
  48.         case '0':
  49.             cout<<"Kraj programa.\n";
  50.         }
  51.     }
  52.     while(odabir!='0');
  53.     //DEALOKACIJA!!!
  54.     deleteQueue(head,tail);
  55.     head=NULL;
  56.     tail=NULL;
  57.     return 0;
  58. }
  59.  
  60. void entry(node *&head, node *&tail, int elt)
  61. {
  62.     //nadopuniti kod
  63.         cout<<"Preuzeli ste listic s rednim brojem za cekanje na nasem jedinom, ali brzom salteru.\n";
  64.     cout<<"Vas broj cekanja u redu je..."<<elt<<endl;
  65.     cout<<"Broj osoba koje cekaju ispred Vas je "<<waitingNum(head)-1<<endl;
  66.         node *newNode=new node;
  67.     newNode->data=elt;
  68.     newNode->link=NULL;
  69.     if(head==NULL)
  70.         head=newNode;
  71.     else
  72.         tail->link=newNode;
  73.     tail=newNode;
  74.  
  75.  
  76. }
  77.  
  78. int process(node *&head, node *&tail)
  79. {
  80.     int elt=head->data;
  81.     node *current=head;
  82.     head=head->link;
  83.     delete current;
  84.  
  85.     return elt;
  86. }
  87.  
  88. bool queueEmpty(node *head)
  89. {
  90.     return (head==NULL);
  91. }
  92.  
  93. void deleteQueue(node *&head, node *&tail)
  94. {
  95.     node *current=head;
  96.     while(current!=NULL)
  97.     {
  98.         current=current->link;
  99.         delete current;
  100.     }
  101. }
  102.  
  103. int waitingNum(node *head)
  104. {
  105.     int num=1;
  106.     while(head)
  107.     {
  108.         num++;
  109.         head=head->link;
  110.  
  111.     }
  112.  
  113.     return num;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement