zoukankan      html  css  js  c++  java
  • practice4_2_stack_struct

    // Practice4_stack.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <stack>
    #include <iostream>
    #include <algorithm>
    #include <stdlib.h>
    #include <time.h>
    #include <string>
    
    using namespace std;//一定不要忘记这句
    
    struct BankLevel
    {
        string name;
        unsigned int level;
    }; /* 开始这里少写一个分号,导致编译不过,教训!!*/
    
    string strs[5] = {"zhonghang", "gonghang", "nonghang", "jianhang", "jiaohang"};
    
    void initStack(stack<BankLevel> &ss, unsigned int size)
    {
        unsigned int num = 0;
        srand(unsigned(time(0)));
        for(unsigned int i = 0; i < size; i++)
        {
            num = rand()%100;
            BankLevel blevel = {strs[i], num};
            ss.push(blevel);
        }
    }
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        stack<BankLevel> ss;
        initStack(ss, 5);
    
        stack<BankLevel> ssCopy(ss);
        cout << "size of ssCopy: " << ssCopy.size() << endl;
    
        while(!ss.empty())
        {
            cout << ss.top().name << "," << ss.top().level << endl;
            ss.pop();
        }
    
        return 0;
    }

    size of ssCopy: 5
    jiaohang,2
    jianhang,31
    nonghang,93
    gonghang,36
    zhonghang,51

  • 相关阅读:
    noip的一些模板(参考了神牛的博客)
    NOIP算法总结与复习
    算是一份学习计划
    RMQ-ST算法的理解与实现(C++)
    SharePoint2010母版页想要的定制
    Memoization
    mutable and immutable
    Sqlite
    PyCharm Change Font Size
    Sublime Text添加gcc编译器
  • 原文地址:https://www.cnblogs.com/liuzc/p/6492915.html
Copyright © 2011-2022 走看看