
大概相当于二维数组,主链表存行,子链表存列
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define success 0
#define fail -1
typedef struct infoin//子链信息
{
int row;
} infoin;
typedef struct nodein//子链节点
{
infoin row;
struct nodein *next;
} nodein;
typedef struct infoout//主链信息
{
nodein *headin;//子链头节点
char *word;//主链自身信息
} infoout;
typedef struct nodeout//主链节点
{
infoout word;
struct nodeout *next;
} nodeout;
int Initout(nodeout *headout)//主链初始化
{
if (headout == NULL)
{
printf("malloc fail in main for headout\n");
return fail;
}
headout->next = NULL;
return success;
}
int lengthout(nodeout *headout)//返回主链长度
{
int len = 0;
nodeout *p = headout;
while (p != NULL)//一直算到尾节点结束
{
len++;
p = p->next;
}
return len-1;//不计

本文介绍如何使用C语言创建和操作二维链表,这种数据结构类似于二维数组,通过主链表保存每一行,子链表则保存每行中的元素。
最低0.47元/天 解锁文章
1072

被折叠的 条评论
为什么被折叠?



