Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- struct LIFOElem
- {
- int key;
- LIFOElem *next;
- };
- LIFOElem *top;
- void zeruj()
- {
- top=NULL;
- }
- void wstaw(int key)
- {
- cout<<"nowy element do stosu"<<endl;
- LIFOElem *pnowy=new LIFOElem;
- pnowy->key=key;
- pnowy->next=top;
- top = pnowy;
- }
- LIFOElem* zwrocElement(int k,LIFOElem* top)
- {
- if(top!=NULL)
- {
- LIFOElem *top2=NULL,*ptr=top,*ptr2=top2;
- while(ptr!=NULL)
- {
- if(ptr->key==k)
- {
- cout<<"znaleziono klucz";
- return ptr;
- }
- else
- {// to powoduje blad
- top2=ptr;
- top2->next=ptr2;
- ptr2=top2;
- ptr=ptr->next;
- }
- }
- }
- cout<<"brak klucza";
- return NULL;
- }
- int main()
- {
- zeruj();
- wstaw(1);
- wstaw(2);
- wstaw(3);
- wstaw(4);
- int K=1;
- zwrocElement(K,top);
- }
Advertisement
Add Comment
Please, Sign In to add comment