Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define STACK_ERR -1000
- using namespace std;
- struct stos
- {
- int liczba;
- stos *next;
- };
- void init(stos *head)
- {
- head->next = NULL;
- }
- void Push(int x, stos *l)
- {
- stos *nowy = new stos;
- nowy->liczba = x;
- nowy->next = l->next;
- l->next = nowy;
- }
- int Pop(stos *l)
- {
- if (l->next == nullptr){
- cout << "Stos jest pusty." << endl;
- return STACK_ERR;
- }
- else
- {
- int el = l->next->liczba;
- void* x = l->next;
- l->next = l->next->next;
- delete x;
- return el;
- }
- }
- void Print(stos *h)
- {
- h = h->next;
- while (h != NULL)
- {
- cout << h->liczba << " ";
- h = h->next;
- }
- cout << endl;
- }
- int main()
- {
- stos stack;
- init(&stack);
- for (int i = 0; i < 10; i++)
- {
- Push(i, &stack);
- }
- Print(&stack);
- for (int i = 0; i < 4; i++)
- {
- Pop(&stack);
- }
- Print(&stack);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement