//应用 反转字符串 先全部入栈,再逐个Top Push#include<iostream>#include<stack>//stack form standard template libraryusingnamespace std;voidReverse(char*C,int n)//n是字符的数量{
stack<char> S;//拥有了一个字符栈//loop(循环) for pushfor(int i =0; i < n; i++){
S.push(C[i]);//调用push函数把字符压入栈}//loop for popfor(int i =0; i < n; i++){
C[i]= S.top();
S.pop();}}intmain(void){char C[5]="hell";Reverse(C,4);
cout << C;//llehreturn0;-[] List item
}
//应用 反转链表 Reverse a Linked List
stack<structNode*> S;
Node* head =NULL;voidReverse_linked_list(){
Node* temp = head;while(temp !=NULL){
S.push(temp);
temp = temp->link;}
Node* temp1 = S.top();
head = temp1;
S.pop();while(! S.empty()){
temp1->link = S.top();
S.pop();
temp1 = temp1->link;}
temp1->link =NULL;}