Practice4_stack_int

stack的第一个练习,push(int)、pop()、top()、empty()函数。

// Practice4_stack.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <stack>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>

using namespace std;//一定不要忘记这句

void initStack(stack<int> &ss, unsigned int size)
{
    int num = 0;
    srand(time(0));
    for(unsigned int i = 0; i < size; i++)
    {
        num = rand()%100;
        ss.push(num);
    }
}

int _tmain(int argc, _TCHAR* argv[])
{
    stack<int> ss;    
    initStack(ss, 5);

    while(!ss.empty())
    {
        cout << ss.top() << endl;
        ss.pop();
    }
    return 0;
}
原文地址:https://www.cnblogs.com/liuzc/p/6491412.html