程序有错误,未调试出来 // test44.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <string> #include <stack> using namespace std; void add_to_bottom(char temp,stack<char> &stack){ if(stack.empty()) stack.push(temp); else{ char temp1=stack.top(); stack.pop(); add_to_bottom(temp,stack); stack.push(temp1); } } void reverse(stack<char>& stack){ if(!stack.empty()){ char temp=stack.top(); stack.pop(); reverse(stack); add_to_bottom(temp,stack); } } void main(int argc, char* argv[]) { stack <char> s1; s1.push('a'); s1.push('b'); s1.push('c'); s1.push('d'); reverse(s1); while(!s1.empty()){ printf("%c ",s1.top()); s1.pop(); } }