删除结点 (双向链表)

#include<stdio.h>
typedef struct DuLNode
{
	int data;
	struct DuLNode *prior;
	struct DuLNode *next;
}DuLNode,* DuLinkList;
void ListDelete(DuLinkList &L,DuLNode *p,int &e)
{
	e=p->data;
	p->prior->next=p->next;
	p->next->prior=p->prior;
	delete p;
}
int main()
{
	int n,i;
	scanf("%d",&n);
	DuLinkList p=new DuLNode;
	DuLinkList L=p;
	for(i=0;i<n;i++)
	{
		DuLinkList s=new DuLNode;
		s->data=i;
		s->prior=p;
		p->next=s;
		p=s;
		L->prior=p;
		p->next=L;
	}
	int e;
	DuLinkList t=L->next->next->next;
	ListDelete(L,t,e);
	p=L->next;
	for(i=0;i<n-1;i++)
	{
		printf("%d ",p->data);
		p=p->next;
	}
	printf("\n");
	return 0;
}

posted @ 2014-07-27 10:04  NYNU_ACM  阅读(223)  评论(0编辑  收藏  举报