📄 list.cpp
字号:
//======================================================================
// list.cpp
//======================================================================
#include "Huffman.h"
template <class list_entry>
list<list_entry>::list()
//constructor
{
head = NULL;
count = 0;
};
template <class list_entry>
list<list_entry>::list(list<list_entry> ©)
//constructor
{
head = copy.head ;
count = copy.size();
};
template <class list_entry>
Node<list_entry>* list<list_entry>::set_position(int position)const
//return a point to the Node in position
//if position == 0 return head ;
//if position == 1 return NULL or head->next ;
{
Node<list_entry>* p = head ;
for( int i = 0 ; i < position ; i++ )
p = p->next;
return p ;
};
template <class list_entry>
int list<list_entry>::ser_position(list_entry xNode)
//to search a position for new node for add or insert
//true to add and false to insert
{
Node<list_entry>* p = head;
int num = 0;
while( p != NULL )
{
if( p->entry >= xNode )
{
return num;
}
p = p->next;
num++;
}
return count;
};
template <class list_entry>
Error_Code list<list_entry>::insert(int position,const list_entry &xNode)
//insert a node to the position
{
if( position < 0 || position > count )
return Position_Range_Erro ;
Node<list_entry>* prev ;
Node<list_entry>* new_node ;
Node<list_entry>* follow ;
if( position > 0 )
{
prev = set_position(position - 1);
follow = prev->next ;
}
else following = head ;
new_node = new Node<list_entry>(xNode,follow);
if( new_node == NULL )
return Overflow ;
if( position == 0 )
head = new_node ;
else
prev->next = new_node ;
count++;
return Insert_Success ;
};
template <class list_entry>
Error_Code list<list_entry>::remove(list_entry *& xNode)
//remove the first node
//keeps a copy to xNode
{
if(count == 0)
return Position_Con_Error;
xNode = head;
head = head->next;
count--;
return Remove_Success;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -