++



         

- 7


int value() { return _value; }

iilst_item* next() { return _next; }

void next( ilist_item *link ) { _next = link; }

void value( int new_value ) { _value = new_value; }

private:

int _value;

ilist_item *_next;

};

display(), ilist_item:

#include <iostream>

class ilist {

public:

void display( ostream &os = cout );

// ...

};

void ilist::

display( ostream &os )

{

os << "\n( " << _size << " )( ";

ilist_item *ptr = _at_front;

while ( ptr ) {

os << ptr->value() << " ";

ptr = ptr->next();

}

os << ")\n";

}

ilist :

#include <iostream>

#include "ilist.h"

int main()

{

ilist mylist;

for ( int ix = 0; ix < 10; ++ix ) {

mylist.insert_front( ix );

mylist.insert_end( ix );

}

cout <<

"Ok: insert_front() insert_end()\n";

mylist.display();

ilist_item *it = mylist.find( 8 );

cout << "\n"

<< " 8: ?"

<< ( it ? " !\n" : " !\n" );

mylist.insert( it, 1024 );

cout << "\n" <<

" 1024 8\n";

mylist.display();

int elem_cnt = mylist.remove( 8 );

cout << "\n"

<< " " << elem_cnt

<< " () 8\n";

mylist.display();

cout << "\n" << " \n";

mylist.remove_front(); mylist.display();

cout << "\n" << " \n";

mylist.remove_all(); mylist.display();