Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- class Stos{
- int *stackT;
- int maxValue, index;
- private:
- int random_num(int scope, int limit){
- return rand()%scope + limit;
- }
- public:
- Stos(int rozmiar){
- init();
- cout<<"Adres obiektu: "<<this<<endl;
- cout<<"Wywolany zostal konstruktor z 1 parametrem"<<endl;
- }
- Stos(){
- init();
- cout<<"Adres obiektu: "<<this<<endl;
- cout<<"Wywolany zostal konstrktor domyslny"<<endl;
- }
- void init(){
- index = 0;
- maxValue = random_num(100, 0);
- stackT = new int[maxValue];
- }
- bool empty(){
- if(index == 0)
- return true;
- else
- return false;
- }
- bool full(){
- if(index == maxValue)
- return true;
- else
- return false;
- }
- void push(int value){
- if(!full())
- stackT[index++] = value;
- else
- cout<<"Stos jest pelny";
- }
- void pop(){
- if(!empty()){
- int *tmp = new int[maxValue];
- index--;
- for(int i = 0; i < index; i++){
- tmp[i] = stackT[i];
- }
- delete [] stackT;
- stackT = tmp;
- }
- }
- int top(){
- if(!empty())
- return stackT[index-1];
- }
- void destroy(){
- delete [] stackT;
- index = 0;
- }
- ~Stos(){
- destroy();
- cout<<"Adres obiektu: "<<this<<endl;
- }
- };
- void dodaj(Stos s, int a) {
- s.push(a);
- }
- main() {
- Stos s;
- s.push(0);
- dodaj(s, 1);
- dodaj(s, 2);
- while (!s.empty()) {
- cout <<
- s.top();
- s.pop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement