/* Kelly & Pohl Exercise 12.11, p. 426 */ /* */ /* Lone Leth Thomsen, 11. April 2003 */ #include #include struct data { char name[10]; int age; int weight; }; typedef struct data DATA; struct linked_list { DATA d; struct linked_list *next; }; typedef struct linked_list ELEMENT; typedef ELEMENT * LINK; LINK cons(DATA d, LINK l){ LINK new_cell; new_cell = (LINK)malloc(sizeof(ELEMENT)); new_cell -> d = d; new_cell -> next = l; return new_cell; }; LINK create_list(DATA arr[],int i){ if (i == 0) return cons(arr[0],NULL); else cons(arr[i],create_list(arr,i-1)); }; int count_r(LINK l,int age, int weight){ if (l == NULL) return 0; else if ((l ->age > age) && (l ->weight> weight)) return(1+ count_r(l->next, age, weight)); else return count_r(l->next, age, weight); };