在一个有序数组中插入一个元素

来源:互联网 发布:网络中继 编辑:程序博客网 时间:2024/05/21 17:11
#include <stdio.h>#include<stdlib.h>int* insert(int *aee, int &n, const int &x){    int i;    for (i = n - 1; i >= 0 && x < aee[i]; i--)    {            aee[i + 1] = aee[i];    }    aee[i+1] = x;    n++;    return aee;}void main(){    int arr[5] = { 1, 2, 3, 5, 6 };    int n = 5;    int x = 4;    insert(arr, n, x);    for (int i = 0; i < n; i++)    {        printf("%d", arr[i]);    }    getchar();}
0 0