Pregled posta

Adresa bloga: https://blog.dnevnik.hr/prirodaa

Marketing

RED,dvostrukopov

#include
using namespace std;

struct node
{
int data;
node *pre, *post;
};

//DEKLARACIJE FUNKCIJA
bool queueEmpty(node* head); //funkcija koja vraća 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 vraća podatak koji se nalazi na početku reda i ujedno briše taj podatak iz reda
void deleteQueue(node*& head,node* &tail); //funkcija koja briše cijeli red = dealokacija
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<<"\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";
cin.get();
entry(head,tail,elt);
elt++;
cin.get();
break;
case '2':
if(!queueEmpty(head)) cout<<"Salter je slobodan. Molimo stranku s rednim brojem: "< else cout<<"Red je prazan, nema kandidata za nove transkacije."< cin.get();
break;
case '3':
cout<<"U redu na salteru ceka "< cin.get();
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=new node;
head->pre=head;
head->post=head;
tail=head;
}
tail->post=newNode;
newNode->pre=tail;
newNode->post=head;
head->pre=newNode;
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..."< cout<<"Broj osoba koje cekaju ispred Vas je "< }

int process(node *&head, node *&tail)
{
int elt;
elt=head->post->data;
node *tmp=head->post;
if (tail==head->post) tail=head;
head->post->post->pre=head;
head->post=head->post->post;
delete tmp;
return elt;
}
bool queueEmpty(node *head)
{
return (head==NULL || head->post==head);
}
void deleteQueue(node *&head, node *&tail)
{
if (head!=0)
{
node *tmp;
tail->post=0;
while (head)
{
tmp=head;
head=head->post;
delete tmp;
}
tail=NULL;
}
}
int waitingNum(node *head)
{
int num=0;
if (head==NULL) return 0;
else if (head==head->post) return 0;
else
{
node *current=head->post;
do
{
num++;
current=current->post;
}
while (current!=head);
}
return num;
}


Post je objavljen 05.06.2012. u 11:24 sati.