Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void push(StackItem** pStack, char c )
- {
- StackItem* p = (StackItem*)malloc(sizeof(StackItem)); // malloc musi się zgadzać z tym na co rzutuje
- if (p)
- {
- memset(p, 0, sizeof(StackItem)); // mallock zawsze z memesetem zero (w sensie wypełniania zerami)
- p->cKey = c;
- p->pNext = *pStack;
- *pStack = p;
- }
- //else cout << "ERROR: stack overflow!!!\n\n";
- }
- //-------------------------
- char pop(StackItem** pStack)
- {
- char c = 0;
- if (c = top(*pStack)) // stos ZNAKOWY nie pusty gdy c != 0
- {
- del(pStack);
- }
- //else cout << "pop(): ERROR: stack underflow!!\n\n";
- return c;
- }
- //-------------------------
- char top(StackItem* pStack)
- {
- if (!isEmpty(pStack))
- return pStack->cKey; // - można używać, ale nie będziemy (*pStack).cKey;
- /*else
- cout << "ERROR: stack underflow!!\n\n"; */
- return 0; // dla stosu liczbowego wypisac komunikat o bledzie
- }
- //-------------------------
- void del (StackItem** pStack )
- {
- if (!isEmpty(*pStack))
- {
- StackItem* p = *pStack;
- *pStack = p->pNext;
- free(p); // funkcja zwalniająca pamięć
- }
- else
- cout << "del(): ERROR: stack underflow!!\n\n";
- }
- //-------------------------
- int isEmpty(StackItem* pStack)
- {
- return !pStack;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement