数据结构-图-在邻接表结构表示的无向图中删除给定的边ij


在这里插入代码片
voidDeletEdge(AdjListg,inti,int j){//在用邻接表方式存储的无向图g中,删除边(i,j)
p=g[i].firstarc;pre=null; //删顶点i的边结点(i,j),pre是前驱指针
while(p)
if(p->adjvex==j){
if(pre==null)
g[i].firstarc=p->next;
elsepre->next=p->next;free(p);
}//释放结点空间。
else{ pre=p;p=p->next; } //沿链表继续查找
p=g[j].firstarc;pre=null; //删顶点j的边结点(j,i),pre是前驱指针
while(p)
if(p->adjvex==i){
if( pre==null )
g[j].firstarc=p->next;
else pre->next=p->next;free(p);
}//释放结点空间。
else{ pre=p;p=p->next; } //沿链表继续查找
}

在这里插入代码片
voidDeletEdge(AdjListg,inti,int j){//在用邻接表方式存储的无向图g中,删除边(i,j)
	p=g[i].firstarc;pre=null;      //删顶点i的边结点(i,j),pre是前驱指针
	while(p)
		if(p->adjvex==j){ 
			if(pre==null)
				g[i].firstarc=p->next;
			elsepre->next=p->next;free(p);
		}//释放结点空间。
		else{  pre=p;p=p->next; }  //沿链表继续查找
		p=g[j].firstarc;pre=null;       //删顶点j的边结点(j,i),pre是前驱指针
		while(p)
			if(p->adjvex==i){
				if( pre==null )
					g[j].firstarc=p->next;
				else pre->next=p->next;free(p);
			}//释放结点空间。
			else{  pre=p;p=p->next; } //沿链表继续查找
}

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM