数据结构 -4.17 笔记

带有头结点的链表,插入和删除时不需要区分插入删除的位置(链头,链中尾)
struct Student{
int num;
char name[20];
double score[3];
double average;
struct Student * next;
};
struct Student *head,*n,*p;
head=(struct Student *)malloc(sizeof(struct Student));

head->num=101//不能在头结点中存放数据

第一个结点
n=(struct Student *)malloc(sizeof(struct Student));
n->num=101;
n->next=NULL;
…为第一个结点的数据域赋值

建立链
head->next=n
p=n;

第二个结点
n=(struct Student *)malloc(sizeof(struct Student));
n->num=101;
n->next=NULL;
…为第一个结点的数据域赋值

建立链
p->next=n;
p=n;

第三个结点
n=(struct Student *)malloc(sizeof(struct Student));
n->num=101;
n->next=NULL;
…为第一个结点的数据域赋值

建立链
p->next=n;
p=n;

struct Student{
int num;
char name[20];
double score[3];
double average;
struct Student * next;};
int main()
{

// struct Student *p;
struct Student *head;
// struct Student *n;
head=(struct Student *)malloc(sizeof(struct Student));
/*p=head;
for(i=0;i<3;i++)
{
n=head=(struct Student )malloc(sizeof(struct Student));
n->num=101+i;
n->next=NULL;
p->next=n;
p=n;
}
/
create(head);
}
void create(struct Student *p)
{
int i;
struct Student *n;
for(i=0;i<3;i++)
{
n=head=(struct Student *)malloc(sizeof(struct Student));
n->num=101+i;
n->next=NULL;
p->next=n;
p=n;
}

}
void del(struct Student *p,int i)
{
int j=0;
while(j<i)
{
p=p->next;
}
p->next=p->next->next;

}


用typedef声明别名(小名)

typedef struct Student{
int num;
char name[20];
double score[3];
double average;
} ElementType;
// typedef char ElmentType;
struct Node{
ElmentType data;//struct Student data;
struct Node *next;
}

数据结构=数据的逻辑结构(一对一,一对多,多对多)+数据的存储结构(存储数据元素自身+数据之间的关系,有顺序存储结构和链式存储结构)+算法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值