【数据结构】 第二章 创建链表
2017-12-29 22:59
429 查看
前言
严蔚敏版数据结构、第二章 创建链表
看代码
思维导图
实现
严蔚敏版数据结构、第二章 创建链表
看代码
//创建链表 //CreateList.cpp //This program is to create two LNode and merge them into one创建两个结点合并成一个链表 # include <iostream> # include <stdlib.h> # include <malloc.h>//动态存储分配头文件 # include <conio.h>//console input/output控制台输入/输出头文件 using namespace std;//# include <iostream>和using namespace std;同时在vs里使用,cout不会报错 # define OK 1 # define ERROR 0 typedef struct LNode //define the LNode structure结点 { int data; struct LNode *next; }LNode, *LinkList; int CreateList(LinkList &head, LinkList s, int x, int y) //CreateList()创建链表 { head = (LinkList)malloc(sizeof(LNode)); //为头结点分配内存空间并定义类型 if (!head)//判断是否分配成功 { cout << endl << "Overflow ! The first LNode isn't allocated !"; return (ERROR); } s = (LinkList)malloc(sizeof(LNode)); //同理,为第二个节点执行相同的操作 if (!s) { cout << endl << "Overflow ! The second LNode isn't allocated !"; return (ERROR); } head->next = s;//指针指向下一个节点,形成链表 s->next = NULL; head->data = x;//数据存储 s->data = y; return (OK); } //CreateList() end void main() //main() function { int x = 10, y = 15; LNode L1, L2;//定义结点 LNode *p1, *p2;//定义指向结点的指针 p1 = &L1; p2 = &L2; cout << endl << endl << "CreateList.cpp"; cout << endl << "=============="; if (CreateList(p1, p2, x, y)) //call CreateList()调用链表创建函数 { cout << endl << endl << "OK! The two LNode are : "; cout << p1->data << "->" << p1->next->data;//对应链表创建函数里的next } cout << endl << endl << "...OK!..."; _getch(); } //main() end //getch();使用时加下划线
思维导图
实现
相关文章推荐
- 数据结构之链表(一)创建,插入,删除
- 数据结构 第二章 线性表 英语成绩表的单链表实现
- 《数据结构》严蔚敏版(java解)——第二章 线性表04 顺序单链表合并
- 数据结构链表 -- 查找倒数第N个元素、中间元素、创建链表
- [数据结构]_[C/C++]_[链表的最佳创建方式]
- 10-数据结构_线性结构-离散存储-链表_创建与遍历链表
- 数据结构之链表操作,创建,插入,删除,查找。
- 数据结构 严蔚敏 清华大学出版社 第二章 抽象数据类型 链表的实现 成功编译并运行
- [数据结构]_[C/C++]_[链表的最佳创建方式]
- 【数据结构】双向链表的创建和读取
- C++数据结构---链表(链表创建)
- 数据结构 第二章 单链表应用举例——一元多项式求和(待补充)
- 剑指offer-第二章数据结构(数组,字符串,链表,树,栈与队列)及例题
- 数据结构学习(二)——单链表的操作之头插法和尾插法创建链表
- 数据结构 双向链表的创建和读取详解及实例代码
- 数据结构:链表的基本操作(创建,删除,插入,逆序,摧毁)
- 数据结构------链表创建与输出
- 目标:完成数组和链表创建队列,完成其余基本数据结构。
- 华南理工数据结构大作业第一题单链表 删除创建等各种简易操作
- 数据结构第二次上机 第二章之单链表