Node *create()
{
	DoubLink *list;
	Node *p, *pNew, *pHead;

	pHead = (Node *)malloc(sizeof(Node));
	pHead->next = NULL;
	pHead->prior = NULL;//第一个节点

	p = pHead; //指针p指向第一个节点

	for(int i = 0; i < 20; i++)
	{
		pNew = (Node *)malloc(sizeof(Node));
		pNew->data = i;

		if(p){
			p->next = pNew;
			pNew->prior = p;
			pNew->next = pHead; //新添加的节点的后驱指向第一个节点
			pHead->prior = pNew; //第一个节点的前驱指向新添加的节点
			p=pNew;	//把p指针指向新添加的节点
		}
	}

	return p;
}

遍历:

void display(Node *linkList)
{
	Node *p = linkList->next->next;

	while(p != linkList->next)
	{
		printf("%d\n", p->data);
		p = p->next;
	}
}


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