싱글 체인 시트 의 중간 노드

#include
using namespace std;

struct ListNode{
	int m;
	ListNode *next;
};

ListNode *Creat ()
{
	ListNode *pHead = nullptr;
	ListNode *p1,*p2;
	p1 = new ListNode;
	cout<>p1->m;
	while(p1->m != 0)
	{
		if(pHead == nullptr)
		{
			pHead = p1;
			p2 = p1;
		}
		else 
		{
			p2->next = p1;
			p2 = p1;
		}
		p1 = new ListNode;
		cout<>p1->m;
	}
	p2->next = nullptr;
	return pHead;
}

void print(ListNode *pHead)
{
	ListNode *p = pHead;
	while(p != nullptr)
	{
		cout<< p->m<< "\t";
		p = p->next;
	}
	cout<next==nullptr)
		return pHead;
	ListNode *pAhead = pHead;
	ListNode *pBehind = pHead;
	/***      ,     ***/
	/*while(pAhead->next != nullptr)
	{
		pAhead = pAhead->next;
		pBehind = pBehind->next;
		if(pAhead->next != nullptr)
			pAhead = pAhead->next;
	}*/

	/***      ,     ***/
	while(pAhead->next!=nullptr&&pAhead->next->next!=nullptr)
	{
		pAhead = pAhead->next->next;
		pBehind = pBehind->next;
	}
	return pBehind;
}
int main ()
{
	ListNode *Head;
	Head = Creat();
	cout<m<

좋은 웹페이지 즐겨찾기