文章标题

来源:互联网 发布:贴吧发广告软件 编辑:程序博客网 时间:2024/06/16 12:38
/*Name: *.cppAuthor: dawangDescription: 插入排序Date: 2017-10-18 16:24Copyright:*/#include <iostream>#include <vector>using namespace std;int main(){    vector<double> ivec;    cout << "请输入数字, ctrl+z 结束" << endl;    double num;    while (cin >> num)    {        ivec.push_back(num);    }    for (vector<double>::iterator i = ivec.begin() + 1; i != ivec.end(); ++i)    {        double key = *i;        for (vector<double>::iterator j = i - 1; j >= ivec.begin(); --j)        {            if (*j > key)                *(j + 1) = *j;            else            {                *(j + 1) = key;                break;            }            // 由于vector的迭代器的数值不允许小于v.begin(), 否则出现中断vector iterator not dereferencable            if (j == ivec.begin())            {                *j = key;                break;            }        }    }    for (vector<double>::iterator index = ivec.begin(); index != ivec.end(); ++index)    {        cout << *index << " ";    }    return 0;}
原创粉丝点击