链表find 操作(23)

mian.cpp


#include <iostream>
#include"exception.h"
#include "Object.h"
#include"SmartPointer.h"
#include"List.h"
#include "SeqList.h"
#include "StaticList.h"
#include"DynamicList.h"
#include "staticarray.h"
#include "dynamicarray.h"
#include "LinkList.h"

using namespace std;
using namespace DTLib;


class Test : public Object{
    int i ;
public:
    Test( int v = 0)
    {
        i=v;
    }
    bool operator ==(const Test& t){
        return (i ==t.i );
    }
};

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

    LinkList< Test> list;
    */
    //这段代码直接报错了? 是因为 没有定义与 Test 对象的 == 操作符重载;怎么解决

    /*
    Test t1(1);
    Test t2(2);
    Test t3(3);

    LinkList< Test> list;
    list.insert(t1);
    list.insert(t2);
    list.insert(t3);

    cout<<list.find(t2)<<endl;
    */
    //在Object 中定义了操作符== !=重载后,可以编译了,但是输出的结果 依然不对
    //因为 他比较的是对应的位置(指针) 并没有 比较 相应的地址
    //要进一步 在 Test  的重写 ==操作符

    Test t1(1);
    Test t2(2);
    Test t3(3);

    LinkList< Test> list;
    list.insert(t1);
    list.insert(t2);
    list.insert(t3);

    cout<<list.find(t3)<<endl;
    return 0;
}

 

问题 来源 自一个时间复杂度 又设立 一种新的需变换遍历(利用游标)


#include <iostream>
#include"exception.h"
#include "Object.h"
#include"SmartPointer.h"
#include"List.h"
#include "SeqList.h"
#include "StaticList.h"
#include"DynamicList.h"
#include "staticarray.h"
#include "dynamicarray.h"
#include "LinkList.h"

using namespace std;
using namespace DTLib;


class Test : public Object{
    int i ;
public:
    Test( int v = 0)
    {
        i=v;
    }
    bool operator ==(const Test& t){
        return (i ==t.i );
    }
};

int main()
{

    LinkList<int> list;
    for(int i=0;i<5;i++){
        list.insert(0,i);
    }
    /*
    for(int i=0;i<list.length();i++){
        cout<<list.get(i)<<endl;
    }*/

    for(list.move(0);!list.end();list.next()){
        cout<<list.current()<<endl;
    }
    //时间复杂度 两种 遍历方式是不一样的
    //自己分析一下时间复杂度
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值