单链表1.c
来自「数据结构涵盖几乎所有的数据结构课程的实现」· C语言 代码 · 共 47 行
C
47 行
#include<stdlib.h>
#include<stdio.h>
struct roommate
{
char name;
long num;
int age;
char birthplace;
struct roommate *next;
};
struct roommate *head,*cthis,*cnew;
void ins_record(void)
{
int i,j=0;
char numstr,b;
cthis=head;
printf("\nInput a num :");
scanf("%d",&i);
while(j<i-2)
{
cthis=(struct roommate*)malloc(sizeof (struct roommate));
cthis=cthis->next;
++j;
}
if(j>i-1)
return;
cnew=(struct roommate*)malloc(sizeof (struct roommate));
printf("\nplease input the information:");
printf("\nenter name:");
scanf("%s", &cnew->name);
printf("\nenter number:");
scanf("%ld",&cnew->num);
printf("\nenter age:");
scanf("%d",&cnew->age);
printf("\nenter birthplace:");
scanf("%s",&cnew->birthplace);
cnew->next=cthis;
}
main()
{
ins_record();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?