Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- struct node
- {
- node *link;
- int data;
- };
- //DEKLARACIJE FUNKCIJA
- bool queueEmpty(node *head); //funkcija koja vraca true ako je red prazan, false ako nije prazan
- void entry(node *&head, node *&tail, int elt); //funkcija koja dodaje element u red
- int process(node *&head,node *&tail); //funkcija koja vraca podatak koji se nalazi na poèetku reda i ujedno brise taj podatak iz reda
- void deleteQueue(node *&head,node *&tail); //funkcija koja brise cijeli red = dealokacija
- int waitingNum(node *head); //funkcija koja vraca broj ljudi u redu
- int main()
- {
- node *head=NULL, *tail=NULL;
- int elt=1;
- char odabir;
- do
- {
- //system("cls");
- cout<<"\n\nBANKA d.d. Glavni izbornik...I-Z-B-O-R-N-I-K"<<endl;
- cout<<"\n1 - Ulaz nove stranke";
- cout<<"\n2 - Obrada stranke";
- cout<<"\n3 - Ispis trenutnog stanja";
- cout<<"\n0 - Kraj";
- cout<<"\n\nUnesite Vas odabir...";
- cin>>odabir;
- cin.ignore(1,'\n');
- switch(odabir)
- {
- case '1':
- cout<<"Klikom na gumb preuzmite listic s brojem cekanja u redu.\n";
- entry(head,tail,elt);
- elt++;
- break;
- case '2':
- if(!queueEmpty(head)) cout<<"Salter je slobodan. Molimo stranku s rednim brojem: "<<process(head,tail)<<" da dodje na salter"<<endl;
- else cout<<"Red je prazan, nema kandidata za nove transkacije."<<endl;
- break;
- case '3':
- cout<<"U redu na salteru ceka "<<waitingNum(head)<<" ljudi.\n";
- break;
- case '0':
- cout<<"Kraj programa.\n";
- }
- }
- while(odabir!='0');
- //DEALOKACIJA!!!
- deleteQueue(head,tail);
- head=NULL;
- tail=NULL;
- return 0;
- }
- void entry(node *&head, node *&tail, int elt)
- {
- //nadopuniti kod
- cout<<"Preuzeli ste listic s rednim brojem za cekanje na nasem jedinom, ali brzom salteru.\n";
- cout<<"Vas broj cekanja u redu je..."<<elt<<endl;
- cout<<"Broj osoba koje cekaju ispred Vas je "<<waitingNum(head)-1<<endl;
- node *newNode=new node;
- newNode->data=elt;
- newNode->link=NULL;
- if(head==NULL)
- head=newNode;
- else
- tail->link=newNode;
- tail=newNode;
- }
- int process(node *&head, node *&tail)
- {
- int elt=head->data;
- node *current=head;
- head=head->link;
- delete current;
- return elt;
- }
- bool queueEmpty(node *head)
- {
- return (head==NULL);
- }
- void deleteQueue(node *&head, node *&tail)
- {
- node *current=head;
- while(current!=NULL)
- {
- current=current->link;
- delete current;
- }
- }
- int waitingNum(node *head)
- {
- int num=1;
- while(head)
- {
- num++;
- head=head->link;
- }
- return num;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement