list 方法的实现

The constructor List

template < class List_entry >

List < List_entry > :: List( )

{

count = 0;

}

clear

template < class List_entry >

voidList < List_entry > :: clear( )

{

count = 0;

}

empty

template < class List_entry >

boolList < List_entry > :: empty( ) const

{

return count <=0;

}

full

template < class List_entry >

boolList < List_entry > :: full( ) const

{

return count >=max_list;

}

replace

template < class List_entry >

Error_code List < List_entry > :: replace( int position , const List_entry &x)

{

if (position < 0 || position >=count) return range_error ;

entry[position ] = x;

return success;

}

retrieve

template < class List_entry >

Error_code List < List_entry > :: retrieve( int position , List_entry &x) const

{

if (position < 0 || position >=count) return range_error ;

x = entry[position ];

return success;

}

 

双向

 

template < class List_entry >

Error_code List < List_entry > :: remove( int position , List_entry &x)

{

Node< List_entry >*prior,*current;

if (count == 0) return fail ;

if (position < 0 || position >=count) return range_error ;

if (position > 0) {

prior= set_position(position − 1) ;

current = prior->next;

prior->next= current->next;

}

else

{

current = head;

head = head->next;

}

x = current->entry;

delete current;

count −−;

return success;

}

posted @ 2013-09-26 18:29  XTQ  阅读(389)  评论(0)    收藏  举报