헤드 노드 헤드 가 있 는 비공 식 단일 체인 시 계 를 지정 하고 체인 시계의 중간 노드 를 되 돌려 줍 니 다.만약 두 개의 중간 결점 이 있다 면, 두 번 째 중간 결점 으로 돌아간다.
650 단어 데이터 구조
#include
#include
#include
typedef int sdatatype;
typedef struct slistnode//
{
sdatatype _data;
struct slistnode *pnext;
}node, *pnode;
typedef struct slist//
{
pnode _phead;
}slist, *pslist;
pnode middlelist(slist *s) {
// 1 0, ,
int count1 = 1;//
int count = 0;//
pnode p1 = s->_phead;
pnode p2 = s->_phead;
while (p1->pnext != NULL) {
p1 = p1->pnext;
count1++;
}
count1 = count1 / 2;
while (count != count1) {
p2 = p2->pnext;
count++;
}
return p2;
}