數據結構-圖-在鄰接表結構表示的無向圖中刪除給定的邊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