Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Stack.h"
- #include "dStack.h"
- #include <iostream>
- #include <stdlib.h>
- using namespace std;
- void Push( StackItem** pHead, char c )
- {
- StackItem* v = (StackItem*)malloc( sizeof(StackItem) );
- if( v ) // v != NULL
- {
- memset( v, 0, sizeof(StackItem) );
- v->cKey = c;
- v->pNext = *pHead;
- *pHead = v;
- }
- }
- char Pop( StackItem** pHead )
- {
- char c = Top( *pHead );
- if( !IsEmpty( *pHead ) ) //jesli stos znakowy nie jest pusty
- {
- Del( pHead );
- }
- else
- {
- cout << "ERROR!" << endl;
- }
- return c;
- }
- char Top( StackItem* pHead )
- {
- if( !IsEmpty(pHead) )
- {
- return pHead->cKey;
- }
- return 0;
- }
- void Del( StackItem** pHead )
- {
- if( !IsEmpty( *pHead ) )
- {
- StackItem* v = *pHead;
- *pHead = v->pNext;
- free( v );
- }
- else
- {
- cout << "ERROR!" << endl;
- }
- }
- int IsEmpty( StackItem* pHead )
- {
- return !pHead;
- }
- void InitStack( StackItem** pHead )
- {
- *pHead = NULL;
- }
- void FreeStack( StackItem** pHead )
- {
- while( !IsEmpty( *pHead ))
- {
- Del( pHead );
- }
- cout << "Stack is Empty!" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement