STL源码-list

这是一个C++模板类List的实现,包含节点结构定义、数据类型别名以及基本操作如push_back、push_front。类中定义了双向链表的节点,并提供了插入元素到链表尾部的功能,但push_front和pop_back方法尚未实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#pragma once
#include<assert.h>
template <class  _Ty>
class list
{
public:
    struct _Node;
    typedef _Node* _Nodeptr;
    struct _Node {
        _Ty value;
        _Nodeptr prev;
        _Nodeptr next;
    };
    typedef _Ty value_type;
    typedef _Ty* pointer_type;
    typedef _Ty& reference_type;
    typedef const _Ty& const_reference_type;
    typedef const _Ty* const_pointer_type;
    typedef int difference_type;
private:
    _Nodeptr _head;
    size_t _size;
public:
    explicit list():_head(_Buynode()),_size(0) {
        
    }
    void push_back(const _Ty value) {
        _Nodeptr _s = _Buynode(_head,_head->prev);
        _s->value = value;
        
        _head->prev->next = _s;
    
        _head->prev = _s;
        _size++;
    }
    void push_front(const _Ty value) {

    }
    void pop_back() {

    }
protected:
    _Nodeptr _Buynode(_Nodeptr _Narg=0,_Nodeptr _Parg=0) {
        _Nodeptr _s = (_Nodeptr)malloc(sizeof(_Node));
        assert(_s != NULL);
        _s->next = _Narg!=0?_Narg:_s;
        _s->prev = _Parg!=0?_Parg:_s;
        return _s;
    }

};
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值