Node *create()
{
	int n = 20;

	Node *pNew, *pTail, *pHead;
	
	pHead = (Node *)malloc(sizeof(Node));
	pHead->next = pHead;//空链表 自己指向自己

	pTail = pHead;	//pTail指针指向pHead节点

	for(int i = 1; i <= n; i++)
	{
		pNew = (Node *)malloc(sizeof(Node));
		if(pNew == NULL)
		{
			printf("error!!");
			exit(0);
		}
		pNew->data = i;
		
		if(pHead->next == pHead)//此时为空链表
		{
			pHead->next = pNew;
			pTail = pNew; //pTail指向新添加的那个节点
		}else{//不是空表的时候
			pTail->next = pNew;
			pTail = pNew;
		}
	}
	
	pTail->next = pHead;//添加完以后把尾指针的指针域指向头节点

	return pTail;
}

posted on 2013-04-25 13:51  纯洁的坏蛋  阅读(603)  评论(0编辑  收藏  举报