基于visual Studio2013解决C语言竞赛题之1093连接链表







题目


解决代码及点评

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

typedef struct	student STU;
struct student
{
	int num;
	char name[10];
	struct student * next;
};
STU * Init93()
{
	STU * p=(STU *)malloc(sizeof(STU));
	if (p==NULL)
	{
		return NULL;
	}
	else
		p->next=NULL;
	return p;
}
void  Insert93(STU * head,int num,char * name)
{	STU * last=head;
	if (last==NULL)
	{
		return;
	}
	while(last->next!=NULL)
		last=last->next;
	STU *p=(STU *)malloc(sizeof(STU));
	if (p==NULL)
	{
		return;
	}
	else
	{
		p->num=num;
		strcpy_s(p->name,name);
		last->next=p;
		p->next=NULL;

	}
}
void	DeleteNode93(STU* pre,STU *cur)
{
	pre->next=cur->next;
	free(cur);
}
void	printfNodes93(STU *head)
{
	STU *p=head->next;
	while(p!=NULL)
	{
		printf("%5d",p->num);
		p=p->next;
	}
	printf("\n");
}
void main()
{
	STU * A=Init93();
	Insert93(A,10,"abc");
	Insert93(A,30,"abc");
	Insert93(A,90,"abc");
    
	STU * B=Init93();
	Insert93(B,45,"abc");
	Insert93(B,100,"abc");
	
	printfNodes93(A);
	printfNodes93(B);
	STU * p1=A->next;
	STU * p2=B->next;
	STU * tempp=A;
	STU * tempB=NULL;
	int flag=1;
	while(p1!=NULL&&p2!=NULL)
	{
		while (p1->num<p2->num&&p1!=NULL)
		{	
			if (p1->next==NULL&&p2!=NULL)
			{
					p1->next=p2;
					flag=0;
					break;
			}
			if (p2==NULL)
			{
				flag=0;
				break;
			}
			p1=p1->next;
			tempp=tempp->next;
		}
		
		if (flag==0)
		{
			break;
		}
		tempB=p2->next;
		tempp->next=p2;
		p2->next=p1;
		p2=tempB;
	}
	printfNodes93(A);
	//printfNodes93(B);
	system("pause");
}


代码编译以及运行

由于资源上传太多,资源频道经常被锁定无法上传资源,同学们可以打开VS2013自己创建工程,步骤如下:

1)新建工程

2)选择工程

3)创建完工程如下图:

4)增加文件,右键点击项目

5)在弹出菜单里做以下选择

6)添加文件

7)拷贝代码与运行


程序运行结果


代码下载

http://download.csdn.net/detail/yincheng01/6681845

解压密码:c.itcast.cn






评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

尹成

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值