⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 walk.h

📁 C++&datastructure书籍源码,以前外教提供现在与大家共享
💻 H
字号:
#ifndef _RANDOMWALK_H#define _RANDOMWALK_H// Owen Astrachan, 6/20/96, modified 5/1/99// class for implementing a one dimensional random walk//// constructor specifies number of steps to take, random walk// goes left or right with equal probability//// two methods for running simulation://// void Simulate()  -- run a complete simulation//// Init(); HasMore(); Next() -- idiom for starting and iterating//                              one step at a time// accessor functions://// int Position()    -- returns x coordinate//                      (# steps left/right from origin)// int Current()     -- alias for GetPosition()//// int TotalSteps()  -- returns total # steps takenclass RandomWalk{  public:    RandomWalk(int maxSteps);  // constructor, parameter = max # steps    void Init();               // take first step of walk    bool HasMore();            // returns false if walk finished, else true    void Next();               // take next step of random walk        void Simulate();           // take all steps in simulation        int Position()   const;     // returns position (x coord) of walker    int Current()    const;     // same as position    int TotalSteps() const;     // returns total # of steps taken      private:      void TakeStep();           // simulate one step of walk    int myPosition;            // current x coordinate    int mySteps;               // # of steps taken    int myMaxSteps;            // maximum # of steps allowed};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -