Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <string>
- #define STOS_MAX 100
- using namespace std;
- template<typename T>class Stos {
- private:
- T data[STOS_MAX];
- int size;
- public:
- Stos() {
- size = 0;
- }
- ~Stos() { }
- int PobierzElementNaGorze() {
- if (size == 0) {
- cout<<"Stos jest pusty!"<<endl;
- return -1;
- }
- return data[size-1];
- }
- void Dodaj(int d) {
- if (size < STOS_MAX)
- data[size++] = d;
- else
- cout<<"Stos jest pełen!"<<endl;
- }
- void Zdejmij() {
- if (size == 0)
- cout<<"Stos jest pusty!"<<endl;
- else
- size--;
- }
- };
- int main()
- {
- Stos<int> obiekt;
- obiekt.Dodaj(22);
- obiekt.Dodaj(32);
- cout<<obiekt.PobierzElementNaGorze()<<endl;
- obiekt.Zdejmij();
- cout<<obiekt.PobierzElementNaGorze()<<endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement