#include typedef struct listcell * cell; struct listcell { int head; cell tail; }; cell cons(int h, cell t) { cell newcell; newcell = (cell) malloc(sizeof(struct listcell)); newcell->head = h; newcell->tail = t; return newcell; } void printlist(cell L) { if (L == NULL) printf("\n"); else { printf("%d ",L->head); printlist(L->tail); } }// printlist int listlength(cell L) { if (L == NULL) return 0; else return 1 + listlength(L->tail); } cell delete1(int x,cell L) // deletes first x from L: nonstructive { if (L == NULL) return L; else if (x == L->head) return L->tail; else return cons(L->head,delete1(x,L->tail)); } cell append(cell A, cell B) { if (A == NULL) return B; else return cons(A->head,append(A->tail,B)); } int doubleit(int x) { return x+x; } int squareit(int x) { return x*x;} cell map( int (*f)(int), cell L ) { if (L == NULL) return L; else cons((*f)(L->head),map(f,L->tail)); } int main() { cell A, B; A = cons(1,cons(3,cons(5,NULL))); B = cons(2,cons(4,cons(6,cons(8,NULL)))); printlist(A); printlist(B); printlist(map(doubleit,A)); printlist(map(squareit,A)); /* B = delete1(6,B); printlist(B); printf("length of B is %d\n",listlength(B)); */ return 0; }