First experience of the list

xiaoxiao2021-03-06  41

/ ******************************************* By C PRIMER 5.11 Chain Representation Corrive * Help via BHQT @ dlut C Friends * ilist.h file *************************************** ************** / # include

using namespace std; class ilist_item {public: ilist_item (int value, ilist_item * item_to_link_to = 0); int value () {return _value;} ilist_item * next () {return _next;} void next (ilist_item * link) {_next = Link;} void value (int new_value) {_value = new_value;} public: ilist_item * _next; int _value;

}; class ilist {public: Void Display (Ostream & OS = Cout); // ilist (); int size (); void insert_front (int value); void insert_end (int value); // void display (); ilist_item * Find (int value); void insert (ilist_item * ptr, int value); ilist (): _AT_FRONT (0), _AT_END (0), _Size (0) {}

Private: ilist (const ilist&; ilist&t&; ilist_item * _at_front; ilist_item * _at_end; int _size;

Void IList :: Display (Ostream & OS) {OS << "/ N (" << _Size << ") ("; ilist_item * ptr = _at_front; while (ptr) {os << Ptr-> Value () << ""; Ptr = ptr -> next ();} OS << "/ n";}

Inline int ilist :: size () {return_size;}

Inline ilist_item :: ilist_item (int value, ilist_item * item): _Value (value) {if (! item) {_next = 0;} else {_next = item -> _ next; item -> _ next = this;}}

Inline void ilist :: INSERT (ILIST_ITEM * PTR, INT VALUE) {if (! ptr) {INSERT_FRONT (VALUE);} else {// Bump_up_size (); new ilist_item (value, ptr);}} inline void ilist :: INSERT_FRONT (INT Value) {ilist_item * ptr = new ilist_item (value); if (! _at_front) {_AT_FRONT = _T_END = PTR;} else {ptr-> next (_AT_front); _AT_FRONT = PTR;} // Bump_up_size (); }

转载请注明原文地址:https://www.9cbs.com/read-71911.html

New Post(0)