#include "Keller.hpp"
#include "datastructure.h"
#include <stdlib.h>
#include <iostream>
usingnamespace std;
int exchange(Keller& D,Keller& E){
Keller C;
C=D;
//cout<<"print C"<<endl;
//C.print();
D=E;
E=C;
//cout<<"print B"<<endl;
//E.print();
//cout<<"print A"<<endl;
//D.print();
}
int main(){
Keller A,B;
datastrct data;
int check;
cout<<"Enter data for A"<<endl;
for (int dum=0;dum<=dim-1;dum++){
cin>>data.list[dum];
}
A.push(data);
cout<<"next value"<<endl;
for (int dum=0;dum<=dim-1;dum++){
cin>>data.list[dum];
}
A.push(data);
cout<<"Enter data for B"<<endl;
for (int dum=0;dum<=dim-1;dum++){
cin>>data.list[dum];
}
B.push(data);
check=exchange(A,B);
cout<<"print A"<<endl;
cout<<endl;
A.print();
cout<<"print B"<<endl;
cout<<endl;
B.print();
}
So far so good. What happens is that the first number of my datastructure datastrct is either zero or some arbitrary number. Probably those are addresses.
As you can see I tried to debug by printing out the exhanged values within the function exchanged. That worked fine. The whole program works also if I just use datastrct and not the class Keller. The class Keller is just a textbook lifo datastructure. datastructure.h is where I define the element of the Keller
lifo datastructure. Question is of course why it doesn't work. If there is a smarter why to do it, by using pointers or so that would be just as helpful.