|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include "def.h" ! 3: ! 4: struct list *consls(v,ls) /* make list */ ! 5: VERT v; ! 6: struct list *ls; ! 7: { ! 8: struct list *temp; ! 9: temp = challoc(sizeof(*temp)); ! 10: temp->elt = v; ! 11: temp->nxtlist = ls; ! 12: return(temp); ! 13: } ! 14: ! 15: struct list *append(v,ls) /* return ls . v */ ! 16: VERT v; ! 17: struct list *ls; ! 18: { ! 19: struct list *temp; ! 20: if (!ls) return(consls(v,0)); ! 21: for (temp = ls; temp -> nxtlist; temp = temp->nxtlist) ! 22: ; ! 23: temp->nxtlist = consls(v,0); ! 24: return(ls); ! 25: } ! 26: ! 27: ! 28: freelst(ls) ! 29: struct list *ls; ! 30: { ! 31: if (!ls) return; ! 32: if (ls->nxtlist) ! 33: freelst(ls->nxtlist); ! 34: chfree(ls,sizeof(*ls)); ! 35: } ! 36: ! 37: ! 38: oneelt(ls) /* return w if w is only elt of ls, UNDEFINED otherwise */ ! 39: struct list *ls; ! 40: { ! 41: if (!ls) return(UNDEFINED); ! 42: if (ls->nxtlist) return(UNDEFINED); ! 43: return(ls->elt); ! 44: } ! 45: ! 46: ! 47: lslen(ls) /* return number of elements in list ls */ ! 48: struct list *ls; ! 49: { ! 50: int count; ! 51: struct list *lp; ! 52: count = 0; ! 53: for (lp = ls; lp; lp = lp->nxtlist) ! 54: ++count; ! 55: return(count); ! 56: } ! 57: ! 58: ! 59: prlst(ls) ! 60: struct list *ls; ! 61: { ! 62: struct list *lp; ! 63: for (lp = ls; lp; lp = lp->nxtlist) ! 64: printf("%d,",lp->elt); ! 65: fprintf(stderr,"\n"); ! 66: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.