结构体和数据结构基础

结构体和数据结构基础

结构体

结构体的定义

struct student{
    long studentID;
    char studentName[10];
    char studentSex;
    int yearOfBirth;
    int score[4];
};

// 给 struct student 一个别名
typedef struct student STUDENT;

单向链表

一种动态数据结构

  • 特点:用一组任意的存储单元存储线性表数据
  • 存储单元可以是连续的,也可以是不连续的

img

  • 链表结构 = 数据域data + 指针域point
  • 头节点的数据域为空,称为头指针
  • 尾节点指针域为空指针
typedef struct Link{
    int data;
    struct Link *next;
}LinkNode, *Plink;

向链表中新建节点

img

Plink addNode(Plink link, int x){
	Plink new = (Plink)malloc(sizeof(LinkNode));
	if(new == NULL)	return NULL;
	new->data = x;
	new->next = link->next;
	link->nexxt = new;
	return 0;
}
posted on 2023-12-15 09:23  GisliW  阅读(3)  评论(0编辑  收藏  举报