⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hebing.c

📁 此程序实现两个有序链表合并成为一个有序链表
💻 C
字号:
#include"Hebinglb.h"
struct node *creat()
{
	int data;
    struct node *h,*p;
	h=(struct node *)malloc(sizeof(struct node));
    h->next=NULL;
	printf("请输入数据,若输入0结束输入:\n");
	scanf("%d",&data);
	while(data!=0)
	{  
	   p=(struct node *)malloc(sizeof(struct node));
	   p->data=data;
	   p->next=h->next;
	   h->next=p;
       printf("请输入数据,若输入0结束输入:\n");
	   scanf("%d",&data);
	}

	return h;
}
void hebing(struct node *ha,struct node *hb)
{
      struct node *p1,*p2,*q1,*q2;
	  p1=ha;
	  p2=ha->next;
	  q1=q2=hb->next;
	  while(p2!=NULL&&q2!=NULL)
	{
      if(p2->data>=q2->data)
	  {
		  q2=q2->next;
		  q1->next=p1->next;
		  p1->next=q1;
		  p1=p1->next;
		  q1=q2;
	  }
	  else
	  {
		  p1=p1->next;
		  p2=p2->next;
	  }
	  

	 }
	  if(p2==NULL)
		  p1->next=q1;
	  if(q2==NULL)
		  p1->next=p2;
}
void out(struct node *h)
{
	struct node *p;
	p=h->next;
	while(p->next!=NULL)
	{
		printf("%d->",p->data);
		p=p->next;
	}
	printf("%d\n",p->data);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -