3. std::forward_list 클래스에도 있는 push_front()pop_front() 함수를 구현합니다.

    public:
        void push_front(int val)
        {
            auto new_node = new node {val, NULL};
            if (head != NULL)
                new_node->next = head;
            head = new_node;
    }
    
    void pop_front()
    {
        auto first = head;
        if (head)
        {
            head = head->next;
            delete first;
        }
    }
    

      4. singly_ll 클래스의 기본 반복자를 구현합니다. 이 반복자는 생성자(constructor)와 접근자(accessor)를 가집니다.

    struct singly_ll_iterator
    {
    private:
        node_ptr ptr;
    
    public:
        singly_ll_iterator(node_ptr p) : ptr(p) {}
        
        int& operator*() { return ptr->data; }
        
        node_ptr get() { return ptr; }
    
    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.