Work20230421

双向链表按位置删除

//双向链表按位置删除
int delete_pos(linklist *L,int pos){
	if(L==NULL || L->next==NULL || pos<1 || pos>L->len)
		return -1;
	linklist *p=L;
	for(int i=0;i<pos-1;i++){
		p=p->next;
	}
	linklist *q=p->next;
	p->next=q->next;
	if(q->next !=NULL){
		q->next->prev=p;
	}
	free(q);
	q=NULL;
	L->len--;
	return 0;
}

双向链表按位置修改

//双向链表位置修改
int modify_pos(linklist *L,int pos, datatyp data){
	if(L==NULL || L->next==NULL || pos<1 || pos>L->len)
		return -1;
	linklist *p=L;
	
	for(int i=0;i<pos;i++){
		p=p->next;
	}
		p->data=data;
	return 0;
}

 双向链表的按位置查找

//双向链表按位置查找
void search_pos(linklist *L,int pos){
	if(L==NULL || L->next==NULL || pos<1 || pos>L->len)
		return;
	linklist *p=L;
	for(int i=0;i<pos;i++){
		p=p->next;
	}
	printf("当前位置的值为:%c\n",p->data);

}

 双向循环链表的头插

linklist *insert_head(linklist *L,datatyp data){
	if(L==NULL){
		return NULL;
	}
	linklist *newnode=create_node(1);
	if(newnode==NULL){
		return NULL;
	}
	newnode->data=data;

	newnode->next=L->next;
	newnode->prev=L;
	if(L->next!=NULL){
		L->next->prev=newnode;
	}
		L->next=newnode;	
	L->len++;
}

 双向循环链表的头删

int delete_head(linklist *L){
	//if..	
	if(L==NULL || L->next==L){
		return -1;
	}

	linklist *q=L->next;
	L->next=q->next;
	if(q->next!=L){
		q->next->prev=L;
	}
	free(q);
	q=NULL;
	L->len--;
	return 0;
}

 双向循环链表的尾删

//尾删
int delete_rear(linklist *L){
	if(L==NULL || L->next==L) return -1;
	linklist *p=L->prev;
	L->prev=p->prev;
	p->prev->next=p->next;
	free(p);
	p=NULL;
	L->len--;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值