Lilst[i-1]=L.list[il;
L.size--;
Returntemp;
}
2.设有一个表头指针为h的单链表。
试设计一个算法,通过遍历一趟链表,将链表中所有结点的链接方向逆转,如下图所示。
要求逆转结果链表的表头指针h
指向原链表的最后一个结点。
(其中有4个空缺,每空3分,共12分)
templatevclassType>voidList:
:
Inverse(){
if(first==NULL)return;
ListNode*p=first->link,*pr=NULL;
while(p!
=NULL){
pr=first;
first=p;
p=p->link;〃指针前移
}
first->link=pr;
}
3.若用二叉链表作为二叉树的存储表示,试以二叉树为参数,交换每个结点的左
子女和右子女问题,编写递归算法:
(其中有3个空缺,每空2分,共6分)
voidBinaryTree:
:
exchange(BinTreeNode*ptr){
BinTreeNode*temp;
if(ptr->leftChild!
=NULL||ptr->rightChild!
=NULL){
temp=ptr->leftChild;
ptr->leftChild=ptr->rightChild;
ptr->rightChild=temp;
exchange(ptr->leftChild);
exchange(ptr->rightChild):
}
Whenyouareoldandgreyandfullofsleep,
Andnoddingbythefire,takedownthisbook,
Andslowlyread,anddreamofthesoftlook
Youreyeshadonce,andoftheirshadowsdeep;
Howmanylovedyourmomentsofgladgrace,
Andlovedyourbeautywithlovefalseortrue,
Butonemanlovedthepilgrimsoulinyou,
Andlovedthesorrowsofyourchangingface;
Andbendingdownbesidetheglowingbars,
Murmur,alittlesadly,howlovefled
Andpaceduponthemountainsoverhead
Andhidhisfaceamidacrowdofstars.
Thefurthestdistaneeintheworld
Isnotbetweenlifeanddeath
ButwhenIstandinfrontofyou
Yetyoudon'tknowthat
Iloveyou.
Thefurthestdistaneeintheworld
IsnotwhenIstandinfrontofyou
Yetyoucan'tseemylove
Butwhenundoubtedlyknowingthelovefromboth
Yetcannotbetogether.
Thefurthestdistaneeintheworld
Isnotbeingapartwhilebeinginlove
ButwhenIplainlycannotresisttheyearning
Yetpretendingyouhaveneverbeeninmyheart.
Thefurthestdistaneeintheworld
Isnotstrugglingagainstthetides
Butusingone'sindifferentheart
Todiganuncrossableriver
Fortheonewholovesyou.
Whenyouareoldandgreyandfullofsleep,
Andnoddingbythefire,takedownthisbook,
Andslowlyread,anddreamofthesoftlook
Youreyeshadonce,andoftheirshadowsdeep;
Howmanylovedyourmomentsofgladgrace,
Andlovedyourbeautywithlovefalseortrue,
Butonemanlovedthepilgrimsoulinyou.
Andlovedthesorrowsofyourchangingface;
Andbendingdownbesidetheglowingbars,
Murmur,alittlesadly,howlovefled
Andpaceduponthemountainsoverhead
Andhidhisfaceamidacrowdofstars.
Thefurthestdistaneeintheworld
Isnotbetweenlifeanddeath
ButwhenIstandinfrontofyou
Yetyoudon'tknowthat
Iloveyou.
Thefurthestdistaneeintheworld
IsnotwhenIstandinfrontofyou
Yetyoucan'tseemylove
Butwhenundoubtedlyknowingthelovefromboth
Yetcannotbetogether.
Thefurthestdistaneeintheworld
Isnotbeingapartwhilebeinginlove
ButwhenIplainlycannotresisttheyearning
Yetpretendingyouhaveneverbeeninmyheart.
Thefurthestdistaneeintheworld
Isnotstrugglingagainstthetides
Butusingone'sindifferentheart
Todiganuncrossableriver
Fortheonewholovesyou.
Whenyouareoldandgreyandfullofsleep,
Andnoddingbythefire,takedownthisbook,
Andslowlyread,anddreamofthesoftlook
Youreyeshadonce,andoftheirshadowsdeep;
Howmanylovedyourmomentsofgladgrace,
Andlovedyourbeautywithlovefalseortrue,
Butonemanlovedthepilgrimsoulinyou.
Andlovedthesorrowsofyourchangingface;
Andbendingdownbesidetheglowingbars,
Murmur,alittlesadly,howlovefled
Andpaceduponthemountainsoverhead
Andhidhisfaceamidacrowdofstars.
Thefurthestdistaneeintheworld
Isnotbetweenlifeanddeath
ButwhenIstandinfrontofyou
Yetyoudon'tknowthat
Iloveyou.
Thefurthestdistaneeintheworld
IsnotwhenIstandinfrontofyou
Yetyoucan'tseemylove
Butwhenundoubtedlyknowingthelovefromboth
Yetcannotbetogether.
Thefurthestdistaneeintheworld
Isnotbeingapartwhilebeinginlove
ButwhenIplainlycannotresisttheyearning
Yetpretendingyouhaveneverbeeninmyheart.
Thefurthestdistaneeintheworld
Isnotstrugglingagainstthetides
Butusingone'sindifferentheart
Todiganuncrossableriver
Fortheonewholovesyou.
Whenyouareoldandgreyandfullofsleep,
Andnoddingbythefire,takedownthisbook,
Andslowlyread,anddreamofthesoftlook
Youreyeshadonce,andoftheirshadowsdeep;
Howmanylovedyourmomentsofgladgrace,
Andlovedyourbeautywithlovefalseortrue,
Butonemanlovedthepilgrimsoulinyou.
Andlovedthesorrowsofyourchangingface;
Andbendingdownbesidetheglowingbars,
Murmur,alittlesadly,howlovefled
Andpaceduponthemountainsoverhead
Andhidhisfaceamidacrowdofstars.
Thefurthestdistaneeintheworld
Isnotbetweenlifeanddeath
ButwhenIstandinfrontofyou
Yetyoudon'tknowthat
Iloveyou.
Thefurthestdistaneeintheworld
IsnotwhenIstandinfrontofyou
Yetyoucan'tseemylove
Butwhenundoubtedlyknowingthelovefromboth
Yetcannotbetogether.
Thefurthestdistaneeintheworld
Isnotbeingapartwhilebeinginlove
ButwhenIplainlycannotresisttheyearning
Yetpretendingyouhaveneverbeeninmyheart.
Thefurthestdistaneeintheworld
Isnotstrugglingagainstthetides
Butusingone'sindifferentheart
Todiganuncrossableriver
Fortheonewholovesyou.