無頭單鏈表面試題

2021-08-03 03:11:22 字數 2341 閱讀 9907

linklist.h

//逆序列印單項鍊表 

void reverseprint(plist plist);

//刪除無頭單鏈表的非尾結點 

void erasenottail(pnode pos);

//在無頭單鏈表的非頭結點前插入乙個元素 

void insertfrontnode(pnode pos, datatype x);

//約瑟夫環問題 

void josephcycle(plist* pplist, int k);

//逆序單向鍊錶 

void reverselist(plist* pplist);

//合併兩個有序列表 

//plist merge(plist* p1, plist* p2); 

plist merge(const plist* p1, const plist* p2);

//查詢單鏈表的中間節點,要求只能遍歷一次鍊錶 

pnode findmidnode(plist plist);

//查詢單鏈表的倒數第k個節點,要求只能遍歷一次鍊錶 

pnode findknode(plist plist, int k);

//判斷鍊錶時候帶環 

pnode checkcircle(plist plist);

//求環的長度 

int getcirclelength(pnode meet);

//求環的入口點 

pnode getcycleentrynode(plist plist, pnode meet);

//判斷兩條單項鍊表時候相交 

int checkcross(plist list1, plist list2);

//求交點 

pnode getcrossnode(plist list1, plist list2);

linklist.c

void reverseprint(plist plist)

printf("%d ",plist->_data);

}void erasenottail(pnode pos)

void insertfrontnode(pnode pos, datatype x)

void josephcycle(plist* pplist, int k)

del = cur->_next;

cur->_data = del->_data;

cur->_next = del->_next;

free(del);

del = null;

}printf("%d ",cur->_data);

}void reverselist(plist* pplist)

}plist merge(const plist* p1, const plist* p2)

if (*p2 == null)

if (cur1->_data < cur2->_data)

else

while (cur1&&cur2)

else

}if (cur1 == null)

}if (cur2 == null)

}return newlist;

}pnode findmidnode(plist plist)

return slow;

}pnode findknode(plist plist, int k)

while (fast->_next != null)

return slow;

}pnode checkcircle(plist plist)

}return null;

}int getcirclelength(pnode meet)

return count;

}pnode getcycleentrynode(plist plist, pnode meet)

return meet;

}int checkcross(plist list1, plist list2)

while (cur2->_next)

if (cur1 == cur2)

else

return 0;

}pnode getcrossnode(plist list1, plist list2)

while (cur2->_next != null)

cur1 = list1;

cur2 = list2;

if (count1 < count2)

}else

}while (cur1 != cur2)

return cur1;}

單鏈表 (面試題)

關於單鏈表的基本操作,之前已經總結過了,那些掌握之後算是了解了單鏈表是什麼?不過現在面試的題中,肯定不會只讓你回答單鏈表的基礎操作,總是會改變一些東西,或是擴充套件一下。下面就是一些關於單鏈表的擴充套件內容 include include include pragma warning disable...

單鏈表面試題

1.倒序列印鍊錶 void reverseprint slistnode pfirst 有兩種方法 1.遞迴操作 2.非遞迴操作 2 非遞迴 slistnode pend slistnode pcur pend null while pfirst pend pend pcur printf d pe...

單鏈表(面試題)

鍊錶反轉思路 1.單鏈表中有效節點的個數 2.查詢單鏈表中弟第k個節點 3.單鏈表的反轉 實現 如下 public class testlink 1單鏈表中有效節點的個數 遍歷得出個數 public static intcount heronode head int count 0 while tr...