310 likes | 472 Vues
アルゴリズムとデータ構造 補足資料 11-4 「第 11 回問題の動作」. 横浜国立大学 理工 学部 数物・電子情報系学科 富井尚志. int main(void) { struct list * listptr , *new1, *new2; listptr = get_list ( ); print_list ( listptr ); new1 = ( struct list *) malloc ( sizeof ( struct list)); new1 -> key = 222;
E N D
アルゴリズムとデータ構造補足資料11-4「第11回問題の動作」アルゴリズムとデータ構造補足資料11-4「第11回問題の動作」 横浜国立大学 理工学部 数物・電子情報系学科 富井尚志
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 listptr
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 listptr key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 listptr key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key next listptr key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 222 next listptr key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 222 next listptr key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 222 next listptr key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 222 next listptr->next->next listptr listptr->next listptr->next->next->next listptr key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> key 222 next key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> key 222 next p p->next p->next->next key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> key 222 next key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> key 222 next key 6 key 5 key 4 key 3 key 2 key 1 next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 listptr key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 listptr key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key next listptr key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 333 next listptr key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 333 next listptr key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 333 next listptr key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 333 next listptr key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> key 333 next key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> tmp key key 333 next next key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> tmp key 333 key 333 next next key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> tmp key 333 key 5 next next key 6 key 5 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> tmp key 333 key 5 next next key 6 key 333 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> tmp key 333 key 5 next next key 6 key 333 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } x p 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> tmp key 333 key 5 next next key 6 key 333 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 5 next listptr key 6 key 333 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 5 next listptr key 6 key 333 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL
int main(void) { struct list *listptr, *new1, *new2; listptr = get_list( ); print_list( listptr ); new1 = (struct list *)malloc(sizeof(struct list)); new1 -> key = 222; func1( new1, listptr->next->next->next); print_list( listptr ); new2 = (struct list *)malloc(sizeof(struct list)); new2 -> key = 333; func2( new2, listptr->next); print_list( listptr ); return 0; } void func1(struct list *x, struct list *p) { x->next = p->next->next; p->next->next = x; } void func2(struct list *x, struct list *p) { struct list tmp; tmp = *x; *x = *p; *p = tmp; p->next = x->next; } 画面出力 <6><5><4><3><2><1> <6><5><4><3><2><222><1> <6><333><4><3><2><222><1> new2 new1 key 5 next listptr key 6 key 333 key 4 key 3 key 2 key 222 key 1 next next next next next next next NULL