请问这个程序是基于c语言的链表吗

来源:百度知道 编辑:UC知道 时间:2024/06/19 10:22:54
#include<stdio.h>
//#include<malloc.h>
struct student
{
char num[10];
char name[10];
int age;
struct student *next;
};

void insert(struct student *t_head);
void input(struct student *pp);
void display(struct student *t_head);

void main()
{
student *head;
head= new student;
head->next=NULL;
int i;
for(i=0;i<4;i++)
insert(head);
display(head);
}

void insert(struct student *t_head)
{
struct student *pt,*ps;
pt= new student;
input(pt);
for(ps=t_head;ps->next!=NULL;ps=ps->next);
pt->next=NULL;
ps->next=pt;
}

void input(struct student *pp)
{
printf("\n Please enter a num: ");
scanf("%s",pp->num);
printf("\n Please enter a name: ");

是基于C的链表
struct student
{
char num[10];
char name[10];
int age;
struct student *next;
};
//---------节点类型为student,包含num、name、age及指向后继的指针

void insert(struct student *t_head);
void input(struct student *pp);
void display(struct student *t_head);
//函数声明

void main()
{
student *head; //定义头节点
head= new student;
head->next=NULL;
int i;
for(i=0;i<4;i++)
insert(head); //调用insert4次,输入4个student信息
display(head); //输出所有节点信息
}

void insert(struct student *t_head)
{
struct student *pt,*ps;
pt= new student; //构造新的节点
input(pt); //输入新节点包含数据
for(ps=t_head;ps->next!=NULL;ps=ps->next); //找到尾节点
pt->next=NULL;
ps->next=pt; //在链表尾插入新节点
}

void input(struct student *pp)
{
printf("\n Please enter a num: ");
scanf("%s"