데이터 구조 - 더 블 링크 의 초기 화 및 삽입, 삭제

10269 단어 데이터 구조
/ / 더 블 링크 작업
#include
#include
typedef struct DNode{
	int data;
	struct DNode *prior,*next;
}DNode,*DLinklist;

//      
bool InitDLinklist(DLinklist &L){
	L=(DNode *)malloc(sizeof(DNode));
	if(L==NULL){
		return false;
	}
	L->prior=NULL;
	L->next=NULL;
	return true;
} 

//      , p      s   
bool InsertNextDNode(DNode *p,DNode *s){
	if(p= =NULL||s==NULL){
		return false;
	}
	s->next=p->next;
	if(p->next!=NULL){
		p->next->prior=s;
	}
	s->prior=p;
	p->next=s;
	return true; 
}
 
//      ,  p    
bool DeleteNextDNode(DNode *p){
	DNode *q;
	if(p= =NULL){
		return false;
	}
	q=p->next;
	if(q==NULL){
		return false;
	}
	p->next=q->next;
	if(q->next!=NULL){
		q->next->prior=p;
	}
	free(q);
	return true;
} 

//        
void DestoryList(DLinklist &L){
	while(L->next!=NULL){
		DeleteNextDNode(L);
	}
	free(L);
	L=NULL;
} 
//    :
while(p!=NULL){
	p=p->next;
} 

//    
while(p!=NULL){
	p=p->prior;
} 

//          
while(p->prior!=NULL){
	p=p->prior;
} 

좋은 웹페이지 즐겨찾기