#include <stdio.h>
#include <malloc.h>
struct rocker {
int data; //保存するデータ
struct rocker *next; //次のボックスのアドレス(鍵)
};
struct rocker *head;
struct rocker *new_rocker(struct rocker *last_rocker)
{
struct rocker *pt;
pt
= malloc(sizeof (struct rocker
)); if (last_rocker) {
last_rocker->next = pt;
}
return pt;
}
void display_rockers(struct rocker *pt)
{
for ( ; pt; pt = pt->next) {
if (pt->next) {
printf("[ data = %d ]->", pt
->data
); } else {
printf("[ data = %d ]\n", pt
->data
); }
}
}
int main()
{
struct rocker *last_rocker;
struct rocker *next;
int i, n;
last_rocker = NULL;
for (i = 0; i < n; i++) {
last_rocker = new_rocker(last_rocker);
if (i == 0) {
head = last_rocker;
}
scanf("%d", &last_rocker
->data
); }
last_rocker->next = NULL;
display_rockers(head);
for (last_rocker = head; last_rocker; last_rocker = next) {
next = last_rocker->next;
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYWxsb2MuaD4KCnN0cnVjdCByb2NrZXIgewogICAgaW50IGRhdGE7IC8v5L+d5a2Y44GZ44KL44OH44O844K/CiAgICBzdHJ1Y3Qgcm9ja2VyICpuZXh0OyAvL+asoeOBruODnOODg+OCr+OCueOBruOCouODieODrOOCuSjpjbUpCn07CgpzdHJ1Y3Qgcm9ja2VyICpoZWFkOwoKc3RydWN0IHJvY2tlciAqbmV3X3JvY2tlcihzdHJ1Y3Qgcm9ja2VyICpsYXN0X3JvY2tlcikKewoJc3RydWN0IHJvY2tlciAqcHQ7CgoJcHQgPSBtYWxsb2Moc2l6ZW9mIChzdHJ1Y3Qgcm9ja2VyKSk7CglpZiAobGFzdF9yb2NrZXIpIHsKCQlsYXN0X3JvY2tlci0+bmV4dCA9IHB0OwoJfQoJcmV0dXJuIHB0Owp9Cgp2b2lkIGRpc3BsYXlfcm9ja2VycyhzdHJ1Y3Qgcm9ja2VyICpwdCkKewoJZm9yICggOyBwdDsgcHQgPSBwdC0+bmV4dCkgewoJCWlmIChwdC0+bmV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