您的位置:首页 > 编程语言 > C语言/C++

C++中将数组线性表转换为链表

2017-10-22 20:12 113 查看
//将数组线性表转换为链表
template<typename T>
void chain<T>::fromList(arrayList<T>&theList)
{
int i = 0;
T temp= theList.get(0);
firstNode = new chainNode<T>(temp, firstNode);
do
{
chainNode<T>*p = firstNode;
int k = 0;
while(k<i)
{
p = p->next;
k++;
}
temp = theList.get(i+1);
p->next = new chainNode<T>(temp, p->next);
listSize++;
i++;
} while (i<theList.size()-1);
listSize++;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: