#pragma once#include單連結串列的面試題"list.h"//
1.逆序列印單連結串列
template
void list::printtailtohead(node *phead)
//2.刪除無頭節點的單連結串列的非尾節點
template
void list::delnontailnode(node *pos)
//3.無頭單連結串列某一節點前插入一個節點
template
void list::insertfrontnode(node*pos, t x)
//4.逆置單連結串列
template
void list::reverselist()
_head =new_head;}//
5.單連結串列的氣泡排序
template
void list::bubblesortoflist()
cur = cur->_next;
}tmp == null ? sign = false : tail =cur;;
}}//
6.中間節點
templatelistnode
* list::middleoflist()
return
slow;}//
7.單連結串列中的倒數第 k 個節點
templatelistnode
* list::reciprocalk(int
k)
while
(tmp)
return
result;}//
8.判斷一個連結串列是否帶環,如果帶環求出環的長度以及入口點
templatelistnode
* list::isringlist()
while (fast ==slow);
cout
<< "
環的節點的個數為:
"<< count <
while (input ==slow)
return
input;}}
return
null;}//
9.判斷兩個連結串列是否相交,如果相交求出交點(不帶環)
templatelistnode
* list::iscross(const list& list1, const list&list2)
while
(tmp2)
tmp1 = list1._head, tmp2 = list2._head; /*
重新指向連結串列的頭
*/int n = abs(length1 -length2);
if (length1 > length2) /*
如果連結串列一 長於 連結串列二
*/ }
else
/*如果連結串列二 長於 連結串列一
*/ }
while
(tmp1)
}return null; /*
沒找到,null 返回*/}
//10.判斷兩個連結串列是否相交,如果相交求出交點(不確定帶不帶環)
templatelistnode
* list::iscrossstrengthen(const list& list1, const list&list2)
}return
false; /*
一個連結串列帶環,一個不帶環
*/}