Код:
#include <iostream>
using namespace std;
class stack{
public:
stack(){
this->id = 0;
this->els = new int(this->id);
}
~stack(){
delete[] this->els;
}
void push(int el){
int *_els = new int(this->id+1);
for(int i=0; i<this->id; i++){
_els[i] = this->els[i];
}
_els[this->id] = el;
delete[] this->els;
this->id++;
this->els = new int(this->id);
for(int i=0; i<this->id; i++){
this->els[i] = _els[i];
}
delete[] _els;
}
int pop(){
this->id--;
return this->els[this->id];
}
int get_id(){
return this->id;
}
private:
int *els, id;
};
int main()
{
stack A, B, C;
A.push(1); A.push(3);A.push(5);A.push(7);
B.push(2);B.push(4);B.push(6);
int _min = min(A.get_id(), B.get_id());
if(_min != 0){
for(int i=0; i < _min; i++){
C.push(A.pop());
C.push(B.pop());
}
}
int count = C.get_id();
for(int i=0; i < count; i++){
cout << C.pop();
}
return 0;
}