Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////
- main.cpp
- ///////////////////////////////////////////////////////////////
- #include <cstdlib>
- #include <iostream>
- #include "stackClass_integer.h"
- using namespace std;
- int main(int argc, char *argv[])
- {
- stackClass_integer newStack(5);
- newStack.pushInt(3);
- newStack.pushInt(4);
- cout << newStack.popInt() << endl;
- newStack.pushInt(7);
- newStack.pushInt(5);
- cout << newStack.popInt() << endl;
- cout << newStack.popInt() << endl;
- cout << newStack.popInt() << endl;
- cout << newStack.popInt() << endl;
- system("PAUSE");
- return EXIT_SUCCESS;
- }
- ///////////////////////////////////////////////////////////////
- stackClass_Integer.h
- ///////////////////////////////////////////////////////////////
- #pragma once
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- class stackClass_integer
- {
- private:
- int numInStack, sizeOfStack, ptrPosition;
- int * stackPtr;
- public:
- stackClass_integer(int numInts);
- void pushInt(int inputValue);
- int popInt();
- ~stackClass_integer(void);
- };
- ///////////////////////////////////////////////////////////////
- stackClass_Integer.cpp
- ///////////////////////////////////////////////////////////////
- #include "stackClass_integer.h"
- stackClass_integer::stackClass_integer(int numInts)
- {
- numInStack = numInts;
- sizeOfStack = sizeof(int) * numInStack;
- stackPtr = (int*) calloc(numInStack,sizeOfStack);
- ptrPosition = 0;
- };
- void stackClass_integer::pushInt(int inputValue)
- {
- if(ptrPosition < numInStack)
- {
- std::cout << "PUSH: ptrPosition #" << ++ptrPosition << " now = "<<inputValue<<std::endl;
- * ++stackPtr = inputValue;
- }
- };
- int stackClass_integer::popInt()
- {
- if(ptrPosition > 0)
- {
- int result = * stackPtr--;
- std::cout << "POP: ptrPosition #" << ptrPosition-- << ": ";
- return result;
- }
- return -1;
- };
- stackClass_integer::~stackClass_integer(void)
- {
- };
Add Comment
Please, Sign In to add comment