栈是仅限在表尾进行插入和删除的线性表。因此对于栈来说,表尾端有着特殊的含义,叫栈顶,对应地,表头端称为栈底。不含元素的空表称为空栈。
栈又称为后进先出的线性表(LIFO)。
栈的应用举例。
1.数制转换(SDUTOJ2131)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
int main()
{
int n,r;
stack<int>sta;
cin>>n>>r;
while(n)
{
sta.push(n%r);
n/=r;
}
while(!sta.empty())
{
cout<<sta.top();
sta.pop();
}
return 0;
}
STL_stack简单介绍2.括号匹配(SDUTOJ2134)
#include<stdio.h>
#include<string.h>
int main()
{
char ch[10000],c;
char stk[10000];
int top,l,i;
while(gets(ch)!=NULL)
{
top=0;
i=0;
while((c=ch[i])!='