//1、逆向打印鏈表(遞歸)
void PrintTailToHead(ListNode *pHead)
{
ListNode *cur = pHead;
if(cur != NULL)
{
PrintTailToHead(cur->_next);
printf( "%d ",cur->_data);
}
}
//2、刪除無頭鏈表中的非尾節點
void DelNoTail(ListNode *pos)
{
assert(pos && pos->_next );
ListNode *next = pos->_next ;
swap(pos->_data ,next->_data );
pos->_next = next->_next ;
free(next);
}
//3、無頭鏈表非頭結點前插入一個節點
void InsertNoHead(ListNode * pos, DataType x)
{
ListNode *tmp = BuyNode(pos->_data );
tmp->_next = pos->_next;
pos->_next = tmp;
pos->_data = x;
}
//4、約瑟夫環問題(假設是一個循環單鏈表)
ListNode* Josephuscycle(ListNode *pHead, DataType x)
{
ListNode *cur = pHead;
while(1)
{
if(cur = cur->_next )
{
return cur;
}
DataType m = x;
while(--x)
{
cur = cur->_next ;
}
ListNode *next = cur->_next ;
swap(cur->_data ,next->_data);
cur->_next = next->_next ;
free(next);
}
}免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。