题解 | #有序序列插入一个数#
有序序列插入一个数
https://www.nowcoder.com/practice/68ae3b28b4a04e098485c4423e2c6548
#include <stdio.h> //插入排序法 int main() { int n = 0; scanf("%d",&n); int arr[100] = {0}; int i,j; for(i=1;i<n+1;i++) { scanf("%d",&arr[i]); } int k = 0; scanf("%d",&k); arr[0] = k; for(i=0;i<n;i++) { if(arr[i+1] < arr[i]) { int mid = 0; mid = arr[i]; arr[i] = arr[i+1]; arr[i+1] = mid; } } for(i=0;i<n+1;i++) { printf("%d ",arr[i]); } }