拼题A 第八题,河南工程学院<数据结构>

本文展示了使用C语言编写的物联网专属数据结构排序代码,主要涉及链表操作,包括插入元素和合并两个已排序链表。代码实现了读取输入数据,将输入值插入到链表末尾,并按升序合并两个链表。对于相等的元素,会进行计数并在输出时只打印一次。
摘要由CSDN通过智能技术生成

1:题目来自拼题A第8题.<河南工程学院>

2:由于本题大部分由作者本人完成少部分参照资料;所以得了18分 少了两份

3:物联网专属,卢老师的<数据结构>

#include<stdio.h>  //HMY自创--盗版必究,,, 全部为自己编写 ;
#include<stdlib.h> //觉得不错就赞下吧; 
struct Sqlist{
	int data;
	struct Sqlist *next;
}sqlist;
int main()
{
	struct Sqlist *L , *L1;
	L=(struct Sqlist *)malloc(sizeof(struct Sqlist));
	L1=(struct Sqlist *)malloc(sizeof(struct Sqlist)); 
	L->next=NULL;
	L1->next=NULL ;
	int temp=1;
    while(scanf("%d",&temp)!=EOF&&temp!=-1)
    { struct Sqlist *p,*he;
      
        p=(struct Sqlist *)malloc(sizeof(struct Sqlist));
    	p->data=temp;
    	he=L;
    	while(he->next!=NULL)
    	{
    		he=he->next;
		}
    	he->next=p;
    	p->next=NULL;
	}
	  while(scanf("%d",&temp)!=EOF&&temp!=-1)
    { struct Sqlist *p,*he;
      
        p=(struct Sqlist *)malloc(sizeof(struct Sqlist));
    	p->data=temp;
    	he=L1;
    	while(he->next!=NULL)
    	{
    		he=he->next;
		}
    	he->next=p;
    	p->next=NULL;
	}
	  struct Sqlist *p1,*p2;
	  p1=L;p2=L1;int i=0,num=0,cnt=0;
	  p1=p1->next;p2=p2->next; 
	  while(p1!=NULL&&p2!=NULL)
{
		if(p1->data<p2->data)
		{
			p1 = p1->next;
		}
		else if(p1->data == p2->data)
		{//cnt为了规范输出 
			num++;		
			if(cnt == 0) 
			{
				cnt = 1;
				printf("%d",p1->data);
			}
			else
			{
				printf(" %d",p1->data);
			}
			p1 = p1->next;
		}
		else
		{
			p2 = p2->next;
		}
	}
	if(num==0)
		printf("NULL");				
}

以上就是小编的全部代码啦.谢谢大家观看 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值