基于visual Studio2013解决C语言竞赛题之1092链表转换







题目


解决代码及点评

/************************************************************************/
/* 
92.	编程把链表(1)变成链表(2)。
head
(1)        data  next       data  next       data  next   

记录1              记录2             记录3

data  next      data  next  

记录4            记录5

head
(2)      data  next       data  next       data  next        

记录1              记录2              记录3        

data  next       data  next  

记录4              记录5


  */
/************************************************************************/
#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 * Init92()
{
	STU * p=(STU *)malloc(sizeof(STU));
	if (p==NULL)
	{
		return NULL;
	}
	else
		p->next=NULL;
	return p;
}
STU *  Insert92(STU * head,int num,char * name)
{	STU * last=head;
	if (last==NULL)
	{
		return NULL;
	}
	while(last->next!=NULL)
		last=last->next;
	STU *p=(STU *)malloc(sizeof(STU));
	if (p==NULL)
	{
		return NULL;
	}
	else
	{
		p->num=num;
		strcpy_s(p->name,name);
		last->next=p;
		p->next=NULL;
		return p;

	}
}
void	DeleteNode92(STU* pre,STU *cur)
{
	pre->next=cur->next;
	free(cur);
}
void	printfNodes92(STU *head)
{
	STU *p=head->next;
	do 
	{
		printf("%5d",p->num);
		p=p->next;
	} while (p!=head->next);
	
	printf("\n");
}
void main()
{
	STU * A=Init92();
	Insert92(A,1,"abc");
	Insert92(A,2,"abc");
	Insert92(A,3,"abc");
    Insert92(A,4,"abc");
	STU*p= Insert92(A,5,"abc");
	p->next=A->next;
	printfNodes92(A);
	STU* a;STU* b;STU*c;
	a=A->next;
	b=a->next;
	c=b->next;
	STU * temp=A->next->next;
	do 
	{
		b->next=a;
		a=b;
		b=c;
		c=c->next;
	} while (b!=temp);
	printfNodes92(A);

	
	system("pause");
}



代码编译以及运行

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

1)新建工程

2)选择工程

3)创建完工程如下图:

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

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

6)添加文件

7)拷贝代码与运行


程序运行结果


代码下载

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

解压密码:c.itcast.cn






posted on 2013-12-10 15:12  三少爷的剑123  阅读(94)  评论(0编辑  收藏  举报

导航