数据结构 第23课 顺序表和单链表的对比分析------------------狄泰软件学院

引用:数据结构第23课、顺序表和单链表的对比分析

main.cpp

#include <iostream>
#include "LinkList.h"
#include "StaticList.h"

using namespace std;
using namespace DTLib;


/* 测试二:  */

class Test : public Object
{
    
    
    int i;
public:
    Test(int v = 0)
    {
    
    
        i = v;
    }

    bool operator == (const Test& obj)
    {
    
    
        return (i == obj.i);
    }
};

int main()
{
    
    
    Test t1(1);
    Test t2(2);
    Test t3(3);

    LinkList<Test> list;   // 单链表对象想要保存的元素是Test对象,并没有查找,但是编译还是会出错,不得已需要重载 ==
                           // 两全其美的方法: 在顶层父类中实现 == 和 !=,,然后自定义类类型继承于Object
    list.insert(t1);
    list.insert(t2);
    list.insert(t3);

    cout << list.find(t3) << endl;

    return 0;
}




/* 测试一:

int main()
{
    LinkList<int> list;

    for(int i=0; i<5; i++)
    {
        list.insert(0,i);
    }


    cout << list.find(-3) << endl;

    return 0;
}
*/


猜你喜欢

转载自blog.csdn.net/dashuu/article/details/115016035
今日推荐