数据结构单链表合并后为什么不能输出Lc
答案:1 悬赏:60 手机版
解决时间 2021-02-13 06:45
- 提问者网友:谁的错
- 2021-02-12 11:01
数据结构单链表合并后为什么不能输出Lc
最佳答案
- 五星知识达人网友:愁杀梦里人
- 2021-02-12 11:14
我自己写过一段一样的代码,用的是链表,你要是有兴趣可以对比一下。
#include
#include
typedef struct node
{
int data;
struct node *next;
}node;
typedef struct list
{
node *h;
int length;
}list;
list l;
node *head1,*head2,*Head;
void initiatesl(node **h)
{
*h = (node*)malloc(sizeof(node));
(*h)->next = NULL;
}
void create_list(node *h,int i)
{
int n = 0;
node *p,*q = h;
for(;n < i;n++)
{
initiatesl(&p);
q->next = p;
scanf("%d",&q->next->data);
q = q->next;
}
}
int merge(node *H,node *h1,node *h2)
{
int n = 0;
node *p = h1->next,*q = h2->next,*r = H,*s = H;
for(;p != NULL && q != NULL;r = r->next,n++)
{
initiatesl(&r->next);
if(p->data < q->data)
{
r->next->data = p->data;
p = p->next;
}
else if(p->data > q->data)
{追问可以帮我改一下我的吗?我不懂哪里出了差错,找不出来
#include
#include
typedef struct node
{
int data;
struct node *next;
}node;
typedef struct list
{
node *h;
int length;
}list;
list l;
node *head1,*head2,*Head;
void initiatesl(node **h)
{
*h = (node*)malloc(sizeof(node));
(*h)->next = NULL;
}
void create_list(node *h,int i)
{
int n = 0;
node *p,*q = h;
for(;n < i;n++)
{
initiatesl(&p);
q->next = p;
scanf("%d",&q->next->data);
q = q->next;
}
}
int merge(node *H,node *h1,node *h2)
{
int n = 0;
node *p = h1->next,*q = h2->next,*r = H,*s = H;
for(;p != NULL && q != NULL;r = r->next,n++)
{
initiatesl(&r->next);
if(p->data < q->data)
{
r->next->data = p->data;
p = p->next;
}
else if(p->data > q->data)
{追问可以帮我改一下我的吗?我不懂哪里出了差错,找不出来
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯