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
    

      

  • 相关阅读:
    js Dom为页面中的元素绑定键盘或鼠标事件
    javascript中DOM获取和设置元素的内容、样式及效果
    第四十一节 固定在顶部的悬停菜单
    第四十节 定位练习
    第三十九节 层级定位
    第三十八节 固定定位
    第三十七节 绝对定位
    第三十六节 相对定位
    第三十五节 定位
    第三十四节 新闻标题练习
  • 原文地址:https://www.cnblogs.com/stonebloom-yu/p/6585694.html
Copyright © 2011-2022 走看看