c++/lists/single-list/int/slist.h
... private: element *e_tail (element *l); int *e_length (element *l); ...
c++/lists/single-list/int/slist.cc
/* * e_tail - given a list, l, return the list without the * head element. * pre-condition: non empty list. * post-condition: return the list without the * first element. * The original list is unaltered. */ element *slist::e_tail (element *l) { return l->next; }
/* * e_length - return the length of element list, l. */ int slist::e_length (element *h) { if (h == 0) return 0; else return (1 + e_length (e_tail (h))); }
/* * length - return the length of list, l. */ int slist::length (void) { return e_length (head_element); }
c++/lists/single-list/int/slist.cc
slist slist::reverse (void) { if (is_empty ()) return *this; else return tail ().reverse().cons (empty().cons (head ())); }
c++/lists/single-list/int/slist.cc
/* * cons - concatenate list, l, to the end of the current list. * pre-condition : none. * post-condition: returns the current list with a copy of * contents of list, l, appended. */ slist slist::cons (slist l) { if (l.is_empty ()) return *this; else return cons (duplicate_elements (l.head_element)); }
c++/lists/single-list/int/slist.cc
/* * cons - concatenate list, l, to the end of the current list. * pre-condition : none. * post-condition: returns the current list with a copy of * contents of list, l, appended. */ slist slist::cons (slist l) { if (l.is_empty ()) return *this; else { int h = l.head (); // use h to force evaluation order return cons (h).cons (l.tail ()); } }
slist slist::cons (slist l) { if (l.is_empty ()) return *this; else return cons (l.head()).cons (l.tail ()); }
This document was produced using groff-1.22.