Witam mam problem z metodą Push ponieważ program wysypuje się przy nałożeniu 2 elementu na stos. Proszę was o pomoc i z góry dziękuję.
tak wygląda definicja klasy
class stack
{
public:
stack();
~stack();
void push(int a);
int pop();
void clear();
bool isempty();
private:
int top;
int *dane;
int size;
};
#include <assert.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include "stack.h"
using namespace std;
stack::stack()
{
this->top=0;
this->size=1;
this->dane=new int[1];
}
stack::~stack()
{
}
void stack::clear()
{
this->top=0;
this->size=1;
}
void stack::push(int a)
{
if(top==(size-1)){
int newsize=2*(this->size);
int *newdane=new int[newsize];
int newtop=newsize-top-1;
int i=newsize;
int x=size;
if(newdane){
for(int k=0;k<top;k++){
newdane[i-k]=this->dane[x-k];
}
this->top=newtop;
this->size=newsize;
this->dane=newdane;
delete[] newdane;
}
this->dane[this->top]=a;
this->top--;
}
else{
this->dane[this->top]=a;
this->top--;
}
}
int stack::pop()
{
this->top--;
return this->dane[this->top+1];
}
bool stack::isempty(){
if( (this->top) == 0 )
return true;
else
return false;
}
else