#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> int main() { int a = 0, b = 0, c = 0,d=0, number = 0; int arr[51] = { 0 }; scanf("%d",&a); for (b = 1; b < a+1; b++) { scanf("%d", &arr[b]); } scanf("%d", &number); arr[0] = number; while ((arr[c] > arr[c + 1])&&c<a) { int tem = arr[c + 1]; arr[c + 1] = arr[c]; arr[c] = tem; c++; } for (d = 0; d < a+1; d++) printf("%d ", arr[d]); return 0; }
var number = parseInt(readline()); var numList = readline().split(' '); var newNum = parseInt(readline()); var a = -1; var b = number; var mid; while(b - a > 1){ mid = parseInt((b + a)/ 2); if(newNum >= numList[mid]){ a = mid; }else{ b = mid; } } numList.splice(a+1, 0, newNum); print(numList.join(' '));