第10章_结构体new.ppt

第10章_结构体new

基本概念 节点---链表中的元素称为节点。 每个节点都包含两部分:数据域和指针域。 根据节点在链表中的位置,又可分为链表的起始节点、中间节点以及结束节点。 链表的结束节点的指针域为空指针NULL * data next head data next data next data NULL 图10-1 链表原理图 举例 #include stdio.h struct st {int x; struct st *next; }; void main( ) {struct st aa[3]={5,aa[1],7,aa[2],9,NULL}; struct st *p; p=aa[0]; printf(%d,++p-x ); } * 两个常用函数 malloc( ) 函数—动态申请内存 如:struct temp { int data; struct temp *next; }; struct temp *p; p=(struct temp *)malloc(sizeof(struct temp)); free( )函数—释放内存 如: free(p); 使用这两个函数时要包含头文件 stdlib.h * 单链表的基本操作 链表的

文档评论(0)

1亿VIP精品文档

相关文档