Code From Class 2026/04/15
#include<iostream>
struct SN{
public:
std::string c;
SN* aN;
};
SN* push(SN* aOT, const std::string& x){
SN* aNT=new SN;
aNT->c=x;
aNT->aN=aOT;
return aNT;
}
SN* pop(SN* aOT){
if(aOT==nullptr){return nullptr;}
SN* aNT=aOT->aN;
delete aOT;
return aNT;
}
SN* flip(SN* aOT){
SN* aNT=nullptr;
while(aOT!=nullptr){
aNT=push(aNT,aOT->c);
aOT=pop(aOT);
}
return aNT;
}
SN* flipInPlace(SN* aOT, SN* aNE=nullptr){
if(aOT==nullptr){return aNE;}
SN* aEmployeeTop=aOT->aN;
aOT->aN=aNE;
return flipInPlace(aEmployeeTop,aOT);
}
void printStack(SN* aT){
SN* runner=aT;
while(runner!=nullptr){
std::cout<<runner->c<<" ";
runner=runner->aN;
}
std::cout<<"\n";
}
int main(){
SN* aT=nullptr;
std::string uI;
std::cin>>uI;
while(uI!="end"){
aT=push(aT,uI);
std::cin>>uI;
}
printStack(aT);
//aT=flip(aT);
aT=flipInPlace(aT);
printStack(aT);
while(aT!=nullptr){aT=pop(aT);}
return 0;
}