• 如何将两个有序的一维数组合并为一个有序的一维数组合


    如何将两个有序的一维数组合并为一个有序的一维数组合


    // merge_array.cpp : 定义控制台应用程序的入口点。
    //


    #include "stdafx.h"
    #include<list>
    #include<iostream>
    using namespace std;


    void myinsert(list<int>&pp, int num);
    int _tmain(int argc, _TCHAR* argv[])
    {
    int a[6] = { 2, 5, 10, 19, 45, 90 };
    int b[4] = { 4, 11, 17, 34 };
    list<int>aa;
    for (int i = 0; i < 6; i++)
    {
    aa.push_back(a[i]);
    }
    for (int i = 0; i < 4; i++)
    {
    myinsert(aa, b[i]);
    cout << b[i] << endl;
    }


    list<int>::iterator iter;
    for (iter = aa.begin(); iter != aa.end(); iter++)
    cout << *iter<<',';
    cout << endl;


    system("pause");
    return 0;
    }


    void myinsert(list<int>&pp, int num)
    {
    list<int>::iterator iter;
    if (num < pp.front())
    pp.push_front(num);
    if (num>pp.back())
    pp.push_back(num);
    for (iter = pp.begin(); iter != pp.end(); iter++)
    {
    if (*iter >= num)
    {
    pp.insert(iter, num);
    cout << pp.size() ;
    cout<<endl;
    break;
    }
    }
    }

    版权声明:

  • 相关阅读:
    Alpha 答辩总结
    Alpha 冲刺报告(10/10)
    Alpha 冲刺报告(9/10)
    Alpha 冲刺报告(8/10)
    Alpha 冲刺报告(7/10)
    Alpha 冲刺报告(6/10)
    团队作业-随堂小测(同学录)
    第一次寒假作业
    寒假学习计划
    1001 A+B
  • 原文地址:https://www.cnblogs.com/walccott/p/4956922.html
Copyright © 2020-2023  润新知