c++ primer plus 例题课后题源代码

源代码在线查看: stkoptr1.cpp

软件大小: 363 K
上传用户: zaindyclg
关键词: primer plus 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				// stkoptr1.cpp -- test stack of pointers
				#include 
				#include      // for rand(), srand()
				#include        // for time()
				#include "stcktp1.h"
				const int Num = 10;
				int main()
				{
				    std::srand(std::time(0)); // randomize rand()
				    std::cout 				    int stacksize;
				    std::cin >> stacksize;
				// create an empty stack with stacksize slots
				    Stack st(stacksize); 
				
				// in basket
				    const char * in[Num] = {
				            " 1: Hank Gilgamesh", " 2: Kiki Ishtar",
				            " 3: Betty Rocker", " 4: Ian Flagranti",
				            " 5: Wolfgang Kibble", " 6: Portia Koop",
				            " 7: Joy Almondo", " 8: Xaverie Paprika",
				            " 9: Juan Moore", "10: Misha Mache"
				            };
				 // out basket
				    const char * out[Num];
				
				    int processed = 0;
				    int nextin = 0;
				    while (processed < Num)
				    {
				        if (st.isempty())
				            st.push(in[nextin++]);
				        else if (st.isfull())
				            st.pop(out[processed++]);
				        else if (std::rand() % 2  && nextin < Num)   // 50-50 chance
				            st.push(in[nextin++]);
				        else
				            st.pop(out[processed++]);
				    }
				    for (int i = 0; i < Num; i++)
				        std::cout 				
				    std::cout 				    return 0; 
				}
							

相关资源