Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //=================
- //TABLICOWO
- //=================
- const int N= 5;
- int sp = 0;
- int stos[N];
- void pushTab(int key)
- {
- if(sp<N)
- {
- stos[sp] = key;
- sp++;
- cout<<"[+]: "<<key<<endl;
- }
- else
- cout<<"[+]: Stos pelny"<<endl;
- }
- int popTab()
- {
- int key;
- if(sp>0)
- {
- sp--;
- key = stos[sp];
- cout<<"[-]: "<<key<<endl;
- }
- else
- cout<<"[-]: Stos pusty"<<endl;
- }
- void drukujTab()
- {
- if(sp == 0)
- cout<<"[STOS] Pusty"<<endl;
- else
- {
- cout<<"[STOS] ";
- for(int i = 0; i< sp; i++)
- cout<< stos[i]<< " ";
- cout<<endl;
- }
- }
- void usunTab()
- {
- if(sp==0)
- cout<<"[USUN] Stos pusty"<<endl;
- else
- {
- cout<<"[USUN] Usunieto caly stos"<<endl;
- for(int i = sp; i>0 ; i--)
- sp--;
- }
- }
- //=================
- //DOWIAZANIOWO
- //=================
- struct element
- {
- int key;
- element *next;
- };
- element *head = 0;
- void pushList(int key)
- {
- element *n = new element;
- n->key = key;
- n->next = head;
- head = n;
- cout<<"[+]: "<< key<< endl;
- }
- void popList()
- {
- if(head == NULL)
- cout<<"[-]: Stos pusty"<<endl;
- else
- {
- cout<<"[-]: "<<head->key<<endl;
- element *n = head;
- head = head->next;
- delete n;
- }
- }
- void drukujList()
- {
- if(head==NULL)
- cout<<"[STOS] Pusty"<<endl;
- else
- {
- cout<<"[STOS]: ";
- element *p = head;
- while(p != NULL)
- {
- cout<<p->key<< " ";
- p = p->next;
- }
- cout<<endl;
- }
- }
- void usunList()
- {
- if(head == NULL)
- cout<<"[USUN] Stos pusty"<<endl;
- else
- {
- element *p;
- while(head!=0)
- {
- p = head->next;
- delete head;
- head = p;
- }
- cout<<"[USUN] Usunieto caly stos"<<endl;
- }
- }
- int main(){
- pushTab(5);
- pushTab(4);
- pushTab(-2);
- pushTab(1);
- pushTab(8);
- drukujTab();
- usunTab();
- pushTab(1);
- pushTab(6);
- pushTab(5);
- pushTab(4);
- pushTab(1);
- popTab();
- pushTab(1);
- pushTab(8);
- drukujTab();
- usunTab();
- drukujTab();
- cout<<endl<<endl<<endl;
- //=========
- pushList(5);
- pushList(-2);
- pushList(10);
- pushList(9);
- pushList(4);
- pushList(5);
- drukujList();
- popList();
- popList();
- drukujList();
- usunList();
- drukujList();
- pushList(10);
- pushList(9);
- drukujList();
- popList();
- drukujList();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement