// 解答6.4 list.c #include #include // 環境によっては不要 typedef enum { false=0, true=1 } bool; // 線形リストの型定義 typedef struct list { int val; struct list *next; } List; // テスト対象のプロトタイプ宣言 void input_list(List*); bool duplicated(const List*); // 入力をリストにして返す void input_list(List *l) { int v; List *p=l; while (scanf("%d", &v)>0) { List *newp = (List*)malloc(sizeof(List)); newp->val = v; p->next = newp; p = p->next; } } // リストの要素の重複を検査する bool duplicated(const List *l) { List *lp = l->next; for (; lp; lp=lp->next) { List *lp2 = lp->next; for (; lp2; lp2=lp2->next) { if (lp->val == lp2->val) return true; } } return false; } List list; int main() { input_list(&list); int d = duplicated(&list); printf("%d\n",d); return 0; }