数据结构与数据库实验报告 201400121076张德良 电工二.docxVIP

  • 3
  • 0
  • 约6.93千字
  • 约 12页
  • 2018-10-13 发布于重庆
  • 举报

数据结构与数据库实验报告 201400121076张德良 电工二.docx

数据结构与数据库实验报告 201400121076张德良 电工二

实验1 ADT表的编程与实现 电工二 姓名:张德良 学号:201400121076 实验目的:加深对抽象数据类型ADT表的理解; 实验原理:参照课本p.44-49,及Figure3.6-3.13. 实验内容:编写程序实现ADT表的定义,及常用操作: 1)、判断表是否为空; 源程序 #include stdafx.h #include stdio.h #include stdlib.h #include malloc.h // 定义链表中的节点 typedef struct node { int member; // 节点中的元素 struct node *pNext; // 指向下一个节点的指针 }Node,*pNode; // 函数声明 pNode CreateList(); // 创建链表函数 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)); 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; } // 遍历链表函数 void TraverseList(pNode pHead) { pNode p = pHead-pNext; while(NULL != p) { printf(%d ,p-member); p = p-pNext; } printf(\n);

文档评论(0)

1亿VIP精品文档

相关文档