c++day7

//vector标准模板库使用
#include 
#include             //链表头文件
#include

using namespace std;

//全局函数作为比较策略
bool Comp(string a, string b)
{
    return a>b;
}

//定义仿函数当做比较策略
class Cop
{
public:
    Cop() {}
    bool operator()(string a, string b)
    {
        return a>b;
    }
};

int main()
{
    //使用无参构造,构造出一个链表
    list s1;            //定义一个链表,每个元素都是一个字符串


    //判空函数
    if(s1.empty())
    {
        cout<<"the list is empty"<b;
//    });


    s1.sort(Cop());             //使用仿函数当做比较策略
    for(auto val:s1)
    {
        cout<
//自己手写标准模板库vector
#include 

using namespace std;

template
class Myvector
{
private:
    T* first;
    T* last;
    T* end;
public:
    //无参构造
    Myvector() {}
    //有参构造
    Myvector(T* f,T* l,T* e):first(new T(f)),last(new T(l),end(new T(e))) {
        cout<<"Myvector::有参构造"<first = new T( *(other.first));
            this->last = new T( *(other.last));
            //this->end = other.end;//浅拷贝
            this->end= new T( *(other.end));//给指针成员单独开辟内存空间, 将原对象的空间中的值放入新的内存空间 深拷贝
        }
        cout<<"Myvector::拷贝赋值函数"<

你可能感兴趣的:(c++,开发语言)