#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
void sort(int* array, int n) ;
typedef struct list {
int number;
struct list* behind;
} list;
void InitList (list* ptr);
int main() {
int n, i, v;
scanf("%d %d", &n, &v); /*输入数组长度*/
getchar();
if (n == 0) { /*判断数组长度是否合理*/
return -1;
}
int array[100] = { 0 }; /*定义数组*/
int* p = array; /*定义指针*/
for (i = 0; i < n; i++) { /*输入n个正整数*/
scanf("%d", array + i);
getchar();
}
//sort(array, n);
list* head = NULL;
list* link = NULL;
int k;
for (k = 0; k < n; k++) {
list* alloc = (list*)malloc(sizeof(list));
alloc->number = array[k];
alloc->behind = NULL;
if (head == NULL) {
head = alloc;
link = alloc;
} else {
link->behind = alloc;
link = link->behind;
}
}
list* new = (list*)malloc(sizeof(list));
if ( v== 0) {
new->number = v;
new->behind = head->behind;
head = new;
} else if (v == n) {
new->number =v;
list* q = head;
while (q->behind) {
q = q->behind;
}
new->behind = NULL;
q->behind = new;
} else {
list* prev = NULL;
list* curr = head;
new->number = v;
while (v) {
prev = curr;
curr = curr->behind;
v--;
}
new->behind = curr;
prev->behind = new;
}
while (head != NULL) {
printf("%d ", head->number);
head = head->behind;
}
// for (i = 0; i < n; i++) {
// printf("%d ", array[i]);
// }
return 0;
}