Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<iomanip>
- #include<cstdlib>
- using namespace std;
- struct node
- {
- node *link;
- int data;
- };
- //DEKLARACIJE FUNKCIJA
- bool stackEmpty(node *head); // funkcija vraæa vrijednost 'true' ako je stog prazan
- void push(node *&head, int n); // funkcija stavlja novi element na stog
- int pop(node *&head); // funkcija brise element sa stoga i vraæa njegov podatkovni dio
- void write(node *head); // funkcija ispisuje elemente koji su na stogu
- void deleteStack(node *&head); // funkcija brise sve elemente sa stoga
- int main(){
- node *s = NULL;
- int elt=1;
- char odabir;
- do
- {
- cout<<"\n\nI-Z-B-O-R-N-I-K"<<endl;
- 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(s,elt);
- elt++;
- break;
- case '2':
- if(!stackEmpty(s))
- {
- cout<<"Preuzet je artikl pod rednim brojem..."<<pop(s)<<endl;
- elt--;
- }
- else cout<<"Skladiste je prazno. Nemate sto preuzeti"<<endl;
- break;
- case '3':
- if(!stackEmpty(s)) write(s);
- else cout<<"Skladiste je prazno."<<endl;
- break;
- case '0':
- cout<<"Kraj programa.\n";
- }
- }
- while(odabir!='0');
- //DEALOKACIJA
- deleteStack(s);
- s=NULL;
- return 0;
- }
- bool stackEmpty(node *head)
- {
- return(head==NULL);
- }
- void push(node *&head, int n)
- {
- node *newNode = new node;
- newNode->data=n;
- newNode->link=head;
- head=newNode;
- }
- int pop(node *&head)
- {
- int n=head->data;
- node *current=head;
- current=head;
- head=head->link;
- delete current;
- return n;
- }
- void write(node *head)
- {
- node *current=head;
- while(current!=NULL)
- {
- cout<<current->data;
- current=current->link;
- }
- }
- void deleteStack(node *&head)
- {
- node *current=head;
- while(current!=NULL)
- {
- current=current->link;
- delete current;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement