2021年数据结构与数据库实验报告
2021年数据结构与数据库实验报告
1 / 17
2021年数据结构与数据库实验报告
试验1 ADT表编程与实现
电工二
姓名: 张德良
学号:
试验目: 加深对抽象数据类型ADT表了解;
试验原理: -49, -.
试验内容: 编写程序实现ADT表定义, 及常见操作:
1)、 判定表是否为空;
源程序
#include ""
#include ""
#include ""
#include ""
// 定义链表中节点
typedef struct node
{
int member; // 节点中元素
struct node *pNext; // 指向下一个节点指针
}Node,*pNode;
// 函数申明
pNode CreateList(); // 创建链表函数
2021年数据结构与数据库实验报告
2021年数据结构与数据库实验报告
2 / 17
2021年数据结构与数据库实验报告
void TraverseList(pNode ); // 遍历链表函数
bool Is_Empty(pNode); // 判定链表是否为空
int main()
{
pNode pHead = NULL; // 定义初始化头节点
struct Node *pHead == NULL
int flag; // 存放链表是否为空标志,
int Len;
pHead = CreateList(); // 创建一个非循环单链表, 并将该链表头结点地址付给pHead
TraverseList(pHead); // 调用遍历链表函数
if (Is_Empty(pHead) == true) // 判定列表是否为空
{
return 0;
}
return 0;
}
// 创建链表函数
pNode CreateList()
{
int i;
int len;
int val;
pNode pHead = (pNode)malloc(sizeof(Node));
2021年数据结构与数据库实验报告
2021年数据结构与数据库实验报告
3 / 17
2021年数据结构与数据库实验报告
pNode pTail = pHead;
pTail->pNext = NULL;
printf("请输入节点个数: ");
scanf("%d",&len);
for(i = 0; i < len; i++)
{
printf("第 %d 个节点数值: ",i+1);
scanf("%d",&val);
pNode pNew = (pNode)malloc(sizeof(Node));
pNew->member = val;
pTail->pNext = pNew;
pNew->pNext = NULL;
pTail = pNew;
}
return pHead;
2022年数据结构与数据库实验报告 来自淘豆网m.daumloan.com转载请标明出处.