📄 hebinglb.cpp
字号:
#include <stdio.h>
#include<stdlib.h>
#define OVERFLOW 0
#define OK 1
#define L 10
typedef struct node {
int data;
struct node *next;
} node;
int iplist(node *h);
int mergelist(node *ha,node *hb);
int oplist(node *h);
void main()
{
node *ha,*hb;
ha=(node*)malloc(sizeof(node));
hb=(node*)malloc(sizeof(node));
iplist(ha);
iplist(hb);
mergelist(ha,hb);
oplist(ha);
}
int iplist(node *h)
{
node *p ;
int a,i,n;
printf("输入节点数:\n");
scanf("%d",&n);
h->next=NULL;
printf("从后往前输入节点内容:\n");
for(i=0;i<n;i++)
{
p=(node*)malloc(sizeof(node));
if(!p)return OVERFLOW;
scanf("%d",&a);
p->data=a;
p->next=h->next;
h->next=p;
}
h->data=i;
return OK;
}
int mergelist(node *ha,node *hb)
{
node *p,*q,*s;
p=ha;
q=hb;
for(;q;)
{
s=(node*)malloc(sizeof(node));
if(!s)return OVERFLOW;
s->data=q->data;
p=ha;
for(;p&&p->next->data!=s->data;)
{
if(p->next->data>s->data)
{
s->next=p->next;
p->next=s;
continue;
}
p=p->next;
/* if(p->next==NULL)
{
s->next=p->next;
p->next=s;
continue;
} */
}
q=q->next;
}
printf("合并后的链表为:\n");
return OK;
}
int oplist(node *h)
{
node *p;
p=h->next;
while (p)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
return OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -