博客作业05--查找

1.学习总结

1.1查找的思维导图

1.2 查找学习体会

查找的内容比较多,类型也比较多,一个题的解法就很多,如果学会一些能直接调用的函数(如map)的用法,解题效率会大大提高,思路也更广。

2.PTA实验作业

2.1 题目1:是否二叉搜索树

2.2 设计思路(伪代码或流程图)


        中序遍历树,并保存前驱节点至prev中
        根据中序遍历是递增的有序列做
	如果当前结点小于前驱结点则不是二叉搜索树 返回false
	否则是二叉搜索树 返回true 

2.3 代码截图

2.4 PTA提交列表说明。

2.1 题目2:二叉搜索树中的最近公共祖先

2.2 设计思路(伪代码或流程图)


        判断u,v是否在树内 不在返回error
	否则继续操作
	若u,v有一个在根上 则返回当前根结点
	若u,v不在同一边树上,则返回当前根结点
	若u,v都在同一边树上,递归调用LCA,直到找到共同祖先 


2.3 代码截图

2.4 PTA提交列表说明。

2.1 题目3:航空公司VIP客户查询

2.2 设计思路(伪代码或流程图)

定义map<string,int>P
输入n和k 

while(n--)
   用name来存身份证号码 len存飞行里程 
   输入 身份证号码和飞行里程 
   存入P[name]中
输入身份证查找乘客
存在输出飞行里程 
否则输出NO info 

2.3 代码截图

2.4 PTA提交列表说明。

3.截图本周题目集的PTA最后排名

3.1 PTA排名

3.2 我的总分:145

4. 阅读代码

#include <map>
struct Test_input_iterator_tag  //数据类型,Move函数中做为参数的原型的基类
{   // identifying tag for input iterators
};

struct Test_output_iterator_tag
{   // identifying tag for output iterators
};

struct Test_forward_iterator_tag
    : public Test_input_iterator_tag, Test_output_iterator_tag
{   // identifying tag for Test_forward iterators
};

struct Test_bidirectional_iterator_tag
    : public Test_forward_iterator_tag
{   // identifying tag for bidirectional iterators
};

struct Test_random_access_iterator_tag
    : public Test_bidirectional_iterator_tag
{   // identifying tag for random-access iterators
};

struct Test_Int_iterator_tag
{   // identifying tag for integer types, not an iterator
};

// POINTER ITERATOR TAGS
struct Test_Nonscalar_ptr_iterator_tag
{   // pointer to unknown type
};
struct Test_Scalar_ptr_iterator_tag
{   // pointer to scalar type
};



template<typename _Tp>
class Test_new_allocator//Linux源码中做为内存分配的基类,在本代码中没有实际用途
{
public:
    typedef size_t     size_type;
    typedef ptrdiff_t  difference_type;
    typedef _Tp*       pointer;
    typedef const _Tp* const_pointer;
    typedef _Tp&       reference;
    typedef const _Tp& const_reference;
    typedef _Tp        value_type;

    template<typename _Tp1>
    struct Test_rebind
    { typedef Test_new_allocator<_Tp1> other; };
    pointer Test_allocator(int size,const void* = 0)
    {
        return new (size * sizeof(_Tp));
    }
    void
        deallocate(pointer __p, size_type)
    { 
        ::operator delete(__p); 
    }
};

总体来说Windows系统Map与Linux系统Map采用了相同的实现思路,只是实现细节有点较小的差异。
同样采用相同的数据结构红黑树做为Map内核链表绑定数据的存储路线(代码内部有Window、Linux系统红黑树相关的实现)。
Map主要分为两大模块调用:
1.Map类:
键值数据的管理以及传送给Tree_node对应的红黑树的节点。
2.Tree_node(节点类):
地址:https://blog.csdn.net/a29562268/article/details/54604572

5. 代码Git提交记录截图

posted @ 2018-05-26 22:35  Littleweii  阅读(286)  评论(1编辑  收藏  举报