【无标题】单链表的应用

单链表的应用


反转单链表

void reserve(linklist head)
{
    
    
	Node *p,*q;
	p=head->next;
	head->next=NULL;
	while(p)
	{
    
    
		q=p->next;
		p->next=head->next;
		head->next=p;
		p=q; 
	}
} 

合并两个单链表

void merge(linklist ha,linklist hb)
{
    
    
	Node *p,*q,*r;
	Node hc;
	p=ha->next;
	q=hb->next;
	r=ha=hc;
	while(q && p)
	{
    
    
		if(p->number<=q->number)
		{
    
    
			r->next=p;
			r=p;
			p=p->next;
		}
		else
		{
    
    
			r->next=q;
			r=q;
			q=q->next;
		}
	}
	if(p) r->next=p;
	if(q) r->next=q;
	free(hb);
} 

猜你喜欢

转载自blog.csdn.net/weixin_61966129/article/details/121455265