前言
在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
