list方法的习题

来源:互联网 发布:网速流量监控软件 编辑:程序博客网 时间:2024/05/19 00:15

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;
}

原创粉丝点击