algorithm
oiglvy
Don't talk to me,show me the code!
展开
-
STL:vector中push_back实现斐波纳契数列计算
/************************************************* 定义:数列第一项和第二项均为1,以后各项都是前两项之和 若该数前面不足两个数,则不足的数缺省为0 例:1、1、2、3、5、8、13、21、34、55..... **************************************************/#include "st原创 2017-03-08 10:39:36 · 303 阅读 · 0 评论 -
STL:algorithm中排序函数sort(升序排列函数)和reverse(反转排列函数)的简单用法
#include "stdafx.h" #include <iostream> #include <algorithm> using namespace std; int main() { int a[8]={8,9,2,6,47,32,16,55}; //char a[8]={'b','f','r','m','q','s','p','a'}也可以,double类型数组也可以原创 2017-03-08 10:13:37 · 771 阅读 · 0 评论 -
递归求阶乘
用递归求数字n的阶乘#include "stdafx.h" #include <iostream> using namespace std; template<typename T> //递归计算 T f(T n) { if(n >1) return n* f(n-1); else return 1; }int main() { int n;原创 2017-03-07 19:14:39 · 213 阅读 · 0 评论 -
链表实现
此程序所写链表,删除功能只能在表尾每次删除一个学生,可在任意合理范围内根据key值插入学生,并打印消息。在查找某个学生位置时,可以考虑写一个search函数,本文在各个函数内直接查找,代码略显冗余。后期有空改进。list.h#ifndef LIST_H_ #define LIST_H_#include "string" #include "iostream" using namespace std;原创 2017-03-10 15:02:12 · 222 阅读 · 0 评论