#include
using namespace std;
struct node
{
int data;
node *link;
};
//DEKLARACIJE FUNKCIJA
bool queueEmpty(node* head);
void entry(node* &head, node*& tail, int elt);
int process(node*& head,node*& tail);
void deleteQueue(node*& head,node* &tail);
int waitingNum(node* head); /funkcija koja vraæa 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"<
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";
cin.get();
entry(head,tail,elt);
elt++;
cin.get();
break;
case '2':
if(!queueEmpty(head)) cout<<"Salter je slobodan. Molimo stranku s rednim brojem: "<
break;
case '3':
cout<<"U redu na salteru ceka "<
break;
case '0':
cout<<"Kraj programa.\n";
}
}
while(odabir!='0');
//DEALOKACIJA!!!
deleteQueue(head,tail);
cin.sync();
cin.get();
return 0;
}
void entry(node *&head, node *&tail, int elt)
{
node *newNode=new node;
newNode->data=elt;
if (head==0)
{
head=newNode;
head->link=head;
}
else
{
tail->link=newNode;
newNode->link=head;
}
tail=newNode;
cout<<"Preuzeli ste listic s rednim brojem za cekanje na nasem jedinom, ali brzom salteru.\n";
cout<<"Vas broj cekanja u redu je..."<
int process(node *&head, node *&tail)
{
int elt;
elt=head->data;
node *tmp=head;
if (head==tail)
{
head=0;
tail=0;
}
else
{
tail->link=head->link;
head=head->link;
}
delete tmp;
return elt;
}
bool queueEmpty(node *head)
{
return (head==NULL);
}
void deleteQueue(node *&head, node *&tail)
{
if (head!=0)
{
node *tmp;
tail->link=0;
while (head)
{
tmp=head;
head=head->link;
delete tmp;
}
tail=NULL;
}
}
int waitingNum(node *head)
{
int num=0;
if (head==NULL) return 0;
else
{
node *current=head;
do
{
num++;
current=current->link;
}
while (current!=head);
}
return num;
}
Post je objavljen 05.06.2012. u 11:25 sati.