• 通讯录链表实现之C++


    前言

    在mooc上学习了链表中的顺序表和单链表,并使用单链表数据结构跟着老师完成通讯录创建。通过这次链表练习使用,做一些总结。

    自顶向下设计探索。

    功能需求

    在功能实现上,通讯录主要包括,创建联系人,删除联系人,显示联系人,退出通讯录。

    通讯录

    1. 创建联系人
      1. 联系人信息
      2. 插入到存储结构中
    2. 删除联系人
      1. 获取删除联系人编号
      2. 删除联系人
    3. 显示联系人
      1. 遍历存储结构
    4. 退出通讯录
      1. 退出控制台

    软件设计

    1. 模块划分
      1. 主控模块(主函数)
      2. 命令读取模块
      3. 命令解析模块
      4. 命令处理模块
    2. 结构划分
      1. 链表结构
        1. 构建函数
        2. 析构函数
        3. 清空
        4. is空
        5. 长度
        6. 获取节点
        7. 节点位置
        8. 前驱
        9. 后继
        10. 插入
        11. 删除
        12. 插入头
        13. 插入尾
        14. 遍历
      2. 节点结构
        1. 数据域
        2. 指针域
        3. 函数
      3. 数据域结构
        1. 姓名
        2. 电话
        3. 函数

    附录:


    链表头文件相关声明定义

    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
    

      

  • 相关阅读:
    (三)索引分区知识详解
    (二)SQL Server分区创建过程
    (一)SQL Server分区详解Partition(目录)
    表格重新加载 where 携带上次值问题
    MongoDB 时差问题问题
    WebAPI跨域处理
    Http请求中 content-type 和 dataType 区别
    那些坑
    微信公众平台开发系列一 ~ 接入前的配置工作
    MVC中登录页图片验证码总结
  • 原文地址:https://www.cnblogs.com/stonebloom-yu/p/6585694.html
Copyright © 2020-2023  润新知