前言
在mooc上学习了链表中的顺序表和单链表,并使用单链表数据结构跟着老师完成通讯录创建。通过这次链表练习使用,做一些总结。
自顶向下设计探索。
功能需求
在功能实现上,通讯录主要包括,创建联系人,删除联系人,显示联系人,退出通讯录。
通讯录
- 创建联系人
- 联系人信息
- 插入到存储结构中
- 删除联系人
- 获取删除联系人编号
- 删除联系人
- 显示联系人
- 遍历存储结构
- 退出通讯录
- 退出控制台
软件设计
- 模块划分
- 主控模块(主函数)
- 命令读取模块
- 命令解析模块
- 命令处理模块
- 结构划分
- 链表结构
- 构建函数
- 析构函数
- 清空
- is空
- 长度
- 获取节点
- 节点位置
- 前驱
- 后继
- 插入
- 删除
- 插入头
- 插入尾
- 遍历
- 节点结构
- 数据域
- 指针域
- 函数
- 数据域结构
- 姓名
- 电话
- 函数
- 链表结构
附录:
链表头文件相关声明定义
List.h
#ifndef LIST_H
#define LIST_H
#include "Node.h"
class List
{
public:
List();
~List();
void ClearList();
bool ListEmpty();
int ListLength();
bool GetElem(int i, Node *pNode);
int LocateElem(Node *pNode);
bool PriorElem(Node *pCurrentNode, Node *pPreNode);
bool NextElem(Node *pCurrentNode, Node *pNextNode);
bool ListInsert(int i, Node *pNode);
bool ListDelete(int i, Node *pNode);
bool ListInsertHead(Node *pNode);
bool ListInsertTail(Node *pNode);
void ListTraverse();
private:
Node *m_pList;
int m_iLength;
};
#endif
节点头文件相关声明定义
Node.h
#ifndef NODE_H
#define NODE_H
#include "Person.h"
class Node
{
public:
Person date;
Node *next;
void printNode();
};
#endif
数据域相关声明定义
Person.h
#ifndef PERSON_H
#define PERSON_H
#include <string>
#include <ostream>
using namespace std;
class Person
{
friend ostream &operator<<(ostream &out, Person &person); //Global Function
public:
string name;
string phone;
Person &operator=(Person &person);
bool operator==(Person &person);
};
#endif
