zoukankan      html  css  js  c++  java
  • 通讯录链表实现之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
    

      

  • 相关阅读:
    在Android中通过导入静态数据库来提高应用第一次的启动速度
    《sqlite权威指南》读书笔记 (一)
    Android APK反编译详解(附图)
    Android如何防止apk程序被反编译
    PopupWindow 学习总结
    Android开源框架Afinal第一篇——揭开圣女的面纱
    教程] 《开源框架-Afinal》之FinalHttp 01一步一脚
    android 下改变默认的checkbox的 选中 和被选中 图片
    Android设置RadioButton在文字的右边
    Android Selector 与 Shape 基本用法
  • 原文地址:https://www.cnblogs.com/stonebloom-yu/p/6585694.html
Copyright © 2011-2022 走看看