谁能给我写一个程序 越简单越好 只要用到 栈 就行 ,最好给我加上注释,谢谢

如题所述

#include <stdio.h>

int stack[100]; /*100个栈空间*/
int* sp = stack; /*栈指针指向栈底*/
#define push( i ) { *sp++ = i; } /*push一个数*/
#define pop() (*--sp) /*pop一个数并返回*/

int main()
{
int i;
for ( i = 0; i < 10; ++i )/*push 0~9*/
push( i );
for ( i = 0; i < 10; ++i )/*输出9~0*/
printf( "%d ", pop() ) ;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-04-25
#include <iostream>
#include <stack>
using namespace std;

int main()
{
stack<int> s;
for (int 1 = 0; i < 5; ++i)
s.push(i);

cout << s.top() << " ";
st.pop();
cout << s.top() << " ";
cout << endl;
}追问

帮忙解释一下吧 谢谢

相似回答