使用链表创建并输出

单链表

#include<stdio.h>
#include<stdlib.h>
struct student
{
	int num;
	char name[10];
	struct student *next;	
};

struct student *creat()
{
	char ch;
	struct student *add,*temp,*head;
	head = (struct student *)malloc(sizeof(struct student));
	head->next = NULL;
	temp = head;
	do
	{
	add=(struct student *)malloc(sizeof(struct student));
	printf("请输入学生的学号和姓名:\n");
	scanf("%d",&add->num);
	scanf("%s",add->name);
	temp->next=add;
	temp=add;
	printf("是否要添加新数据:(Y/N)");
	fflush(stdin);
	ch=getchar();
	}while(ch=='y'||ch=='Y');
	temp->next=NULL;
	return head;
} 


int main()
{
	struct student *temp;
	temp=creat()->next;
	while(temp!=NULL)
	{
		printf("学号为:%d",temp->num);
		printf("姓名为:%s",temp->name);
		temp=temp->next;
	}	
}

这里使用链表创建并输出了信息,为以后管理系统铺垫。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值