将两个递增链表中B链表插入A中,保持增序,但不改变B,请大师帮看下对么?

u010423430 2013-11-02 05:35:12
将两个递增链表中B链表插入A中,保持增序,但不改变B
void Great_link(*ha,*hb)
{
struct *current_1,*current_2;
struct *temp;
current_1=hb->next;
while(current_1->next!=NULL)
{
if(ha->next->data>current_1->data)
current_2=(*struct)malloc(sizeof(struct));
current_2->data=current_1->data;
current_2->next=ha->next;
ha->next=current_2;
ha=current_2;
current_1=current->next;
else if(ha->next->data=current_1->data)
current_1=current_1->next;
else
ha=ha->next;
while(ha->next==NULL)
current_2=(*struct)malloc(sizeof(struct));
current_2->data=current_1->data;
ha->next=current_2;
current_2->next=NULL;
ha=current_2;
current_1=current_1->next;
}
}
...全文
133 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
一根烂笔头 2013-11-03
  • 打赏
  • 举报
回复
你没有结构体啊,大致看了一下,有点乱,我还是给你写了一个,供参考。

struct node 
{
	int data;
	struct node *next;
};

void Great_link(struct node *ha,struct node *hb)
{
	struct node  *p,*q, *s;
	struct node *temp;

	p = ha->next;
	q = hb->next;

	while(q)
	{
		if (p->data < q->data)
		{
			p = p->next;
			continue;
		}
		
		//无论插入到哪里,不改变b那么就要新建结点
		temp = (struct node *)malloc(sizeof(struct node));
		temp->data = q->data;

		//将temp插入到p之后
		temp->next = p->next;
		p->next = temp;

		//如果p->data = q->data不做处理,如果p->data > q->data,把数据交换一下即可
		if (p->data > q->data)
		{
			temp->data = p->data;
			p->data = q->data;
		}

		p = temp;//p下移
		if (q)
		{
			q = q->next;
		}
		else
			break;//链表b处理完毕
		
		if (p->next == NULL)
		{
			s = p;//为下一个while提供服务
		}
		
	}
	
	while(q)//到a末尾,b未处理完毕
	{
		temp = (struct node *)malloc(sizeof(struct node));
		temp->data = q->data;

		temp->next = s->next;//实际上就是NULL
		s->next = temp;
		s = temp;
		q = q->next;
	}
} 

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧