#include #include #include #define LEN1 1000000 /* 対象の配列/リストの長さ */ #define LEN2 1000 /* 対象の配列/リストに挿入するもう一つの配列/リストの長さ */ struct cell { int content; struct cell *next; }; struct cell * add(int x, struct cell *p) { struct cell *q; q = (struct cell *) malloc(sizeof(struct cell)); q->content = x; q->next = p; return q; } void insert_list(struct cell *pos, struct cell *first, struct cell *last) { /* pos が指している対象の線形リストのノードの直後にもう一つの線形リスト を挿入する関数。 first, last は挿入される線形リストの最初と最後のノードを指すポインタ。 */ last->next = pos->next; /* 先ず、挿入されるリストの最後のノードを pos の直後のノードとつなげる */ pos->next = first; /* そして pos を、挿入されるリストの最初のノードとつなげる */ } int *insert_array(int a1[], int a2[], int pos) { /* 配列 a1 の pos 番目(インデックスがpos-1)の要素の直後に配列 a2 の要素を挿入した新しい配列(new) を返す関数。 */ int *new; int new_size = LEN1+LEN2; /* 両方の配列の要素が入り切れるように長さを合計にする */ int i; new = (int *)malloc(sizeof(int)*new_size); /* 関数で作られた配列を返すからメモリの動的確保をする */ /* a1 と a2 の全要素を new にコピーする */ for (i=0; i=pos; i--) { /* a1 の残りの部分を後ろからコピー */ new[i+LEN2] = a1[i]; } for (i=0; i