栈2--堆栈数组模拟

开始学习栈之间,通过数字进制之间的转换来熟悉栈的先进后出(LIFO)思想。

//堆栈的数组模拟
#include<iostream>
using namespace std;
//数据初始化
const int size=100;
int a[size+1];

//处理函数

int main(){
    //数据初始化
    int n,d,i=0,j;
    cout<<"Please input a number (N) base 10:";
    cin>>n;
    cout<<"Pleasee enter a nuber(d):";
    cin>>d;

    //事务处理
    do{
        a[++i]=n%d;
        n=n/d;
    }while(n!=0);
    for(j=i;j>=1;j--){
        cout<<a[j];
    }

    //输出数据

    return 0;
}
发布了120 篇原创文章 · 获赞 23 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/qew2017/article/details/104857789
今日推荐