luzicheng66
luzicheng66
2017-09-27 15:12

求助数据结构题目怎么做

  • 算法

#include

using namespace std;

class SomeFunction{
public:
int a, b, c;
void generate(int);
};

void SomeFunction::generate(int n){
a = 0; b = 1;
cout << a << " " <<b;
for(int i=1; i<= n-2; i++){
c = a + b;
cout << " " << c;
a = b;
b = c;
}
}

int main()
{
cout << "Hello world! SomeFunction works" << endl;
cout << "Enter number of items you need in the series: ";
int n;
cin >> n;
SomeFunction somefun;
somefun.generate(n);
return 0;
}
(1)说明算法功能,并且评价generate()算法复杂度。
(2)采用递归方式改写generate()算法,并且分析复杂度。

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答