Pregled posta

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

Marketing

stog,dvostr pov

#include
#include
using namespace std;

struct node
{
int data;
node *pre, *post;
};
//DEKLARACIJE FUNKCIJA
bool stackEmpty(node*); // funkcija vraća vrijednost 'true' ako je stog prazan
void push(node*&, int); // funkcija stavlja novi element na stog
int pop(node*&); // funkcija briše element sa stoga i vraća njegov podatkovni dio
void write(node*); // funkcija ispisuje elemente koji su na stogu
void deleteStack(node*&); // funkcija briše sve elemente sa stoga

int main(){

node *stack = NULL;
int elt=1;
char odabir;
do
{
cout<<"\n\nI-Z-B-O-R-N-I-K"< cout<<"\n1 - Unos novog primjerka";
cout<<"\n2 - Preuzimanje artikla";
cout<<"\n3 - Ispis trenutnog stanja skladista";
cout<<"\n0 - Kraj";
cout<<"\n\nUnesite Vas odabir...\n";
cin>>odabir;
switch(odabir)
{
case '1':
push(stack,elt);
elt++;
cin.get();
break;
case '2':
if(!stackEmpty(stack))
{
cout<<"Preuzet je artikl pod rednim brojem..."< elt--;
}
else cout<<"Skladiste je prazno. Nemate sto preuzeti"< cin.get();
break;
case '3':
if(!stackEmpty(stack)) write(stack);
else cout<<"Skladiste je prazno."< cin.get();
break;
case '0':
cout<<"Kraj programa.\n";
}
}
while(odabir!='0');
//DEALOKACIJA
deleteStack(stack);
cin.sync();
cin.get();
return 0;
}
bool stackEmpty(node *head)
{
if (head==0 || head->post==head) return true;
else return false;
}

void push(node *&head, int elt)
{
if (head==0)
{
head=new node;
head->pre=head->post=head;
}
node *newNode=new node;
newNode->data=elt;
newNode->pre=head;
newNode->post=head->post;
head->post->pre=newNode;
head->post=newNode;
}

int pop(node *&head)
{
int elt;
node *current=head->post;
elt=current->data;
head->post=current->post;
current->post->pre=head;
delete current;
return elt;
}
void write(node *head)
{
node *current=head->post;
while (current!=head)
{
cout<data;
current=current->post;
}
cout< }
void deleteStack(node *&head)
{
if (head)
{
node *current=head->post, *tmp;
while(current!=head)
{
tmp=current;
current=current->post;
delete tmp;
}
delete head;
head=NULL;
}
}


Post je objavljen 05.06.2012. u 11:21 sati.