++


         

8.



8.
1 class list_node;
2
3 class linked_list
4 {
5 int number_of_elements_in_list;
6 list_node *root;
7
8 private: // ,
9 friend class list_node; // list_node
10 void have_removed_an_element(void)
11 {
12 --number_of_elements_in_list;
13 }
14
15 public:
16 void remove_this_node( list_node *p )
17 {
18 // ,
19 // , list_node
20 // remove_yourself_from_me( &root ).
21
22 p->remove_yourself_from_me( &root );
23 }
24
25 // ...
26 };
27
28 class list_node
29 {
30 linked_list *owner;
31 private: //
32 friend class linked_list; // ,
33 // linked_list
34 void remove_yourself_from_me( list_node *root )
35 {
36 // ...
37 owner->have_removed_an_element();
38 }
39 };
9.
1 class list_node;
2
3 class linked_list
4 {
5 int number_of_elements_in_list;
6 list_node *root;
7
8 private:
9 friend class list_node;
10 void have_removed_an_element( void );
11
12 public:
13 void remove_this_node( list_node *p );
14
15 //...
16 };
17 //========================================================
18 class list_node
19 {
20 linked_list *owner;
21 private: // ,
22 friend class linked_list; //
23 // linked_list
24
25 void remove_yourself_from_me( list_node *root );
26 };
27
28 //========================================================
29 // linked_list:
30 //========================================================
31 inline void
linked_list::remove_this_node( list_node *p )
32 {
33 p->remove_yourself_from_me( &root );
34 }
35 //--------------------------------------------------------
36 inline void
linked_list::have_removed_an_element( void )
37 {
38 --number_of_elements_in_list;
39 }
40
41 //========================================================
42 // list_node:
43 //========================================================
44 void list_node::remove_yourself_from_me( list_node *root )
45 {
46 // ...
47 owner->have_removed_an_element();
48 }