<commit_before>/**
 * @file aghDlist.h
 * @author <NAME>, <NAME>
 * @date 19|05|2016
 * @version 0.1
 * @brief Contains declaration and definition of aghDlist template class.
*/

// --------------------------------------------------------------------------------

#ifndef DATA_CONTAINER_AGHLIST_H
#define DATA_CONTAINER_AGHLIST_H

#include "aghContainer.h"
#include <iostream>

using namespace std;

/**
 * Class template to provide operations on double-sided list
*/
template<typename T>
class aghDlist :
         public aghContainer<T> {
public:
    aghDlist();

    aghDlist(const aghContainer<T> &);

    ~aghDlist();

    /**
     * Insert an element at specified position.
     * @param position number
     * @param new element
     */
    bool insert(const int, const T &);

    /**
     * Get element at specified position
     * @param position number
     * @return reference to the value
     */
    T & at(const int) const;

    /**
     * Get size of the container.
     * @return int size
     */
    int size(void) const;

    /**
     * Remove element at specified position.
     * @param position number
     * @return bool
     */
    bool remove(const int);

    /**
     * Remove all elements from the container.
     */
    void clear(void);

    /**
     * Assignment operator
     *
     * @param another vector
     * @return reference to the object
     */
    aghContainer<T> &operator=(const aghContainer<T> &);

private:
    template<typename Y>
    struct Node{
        Y value;
        Node<Y> * next;
        Node<Y> * prev;

        Node(Y value, Node* next = nullptr, Node* prev = nullptr) : value(value), next(next), prev(prev) {}
    };

    typedef Node<T> *listElem ;

    listElem head;
    listElem tail;

    unsigned int elements;

    listElem getNode(int) const;
};

// --------------------------------------------------------------------------------
// End of aghDlist declaration.
// --------------------------------------------------------------------------------

template<typename T>
aghDlist<T>::aghDlist() : head(nullptr), tail(nullptr), elements(0) {}

// --------------------------------------------------------------------------------

template<typename T>
aghDlist<T>::aghDlist(const aghContainer<T> &container) : head(nullptr), tail(nullptr) {
    this->copy(container);
}

// --------------------------------------------------------------------------------

template<typename T>
aghDlist<T>::~aghDlist() {
    this->clear();
}

// --------------------------------------------------------------------------------

template<typename T>
bool aghDlist<T>::insert(const int index, const T& value) {
    if (index > this->elements || index < 0)
        return false;

    listElem tmp;
    listElem newElem;
    
    newElem = new Node<T>(value);
    
    if(index > 0) {
        oldElem = this->getNode(index-1);
        newElem -> prev = oldElem;
        newElem -> next = oldElem -> next;
        oldElem -> next = newElem;
        if(index != this->elements) 
            (newElem->next)->prev = newElem;
    }
    else {
        newElem -> next = this->head;
        this->head = newElem;
        if(index != this->elements)
            (newElem->next)->prev = newElem;
    }
    
    if(index != this->elements)
        (newElem->next)->prev = newElem;
    else
        this->tail = newElem;
    ++(this->elements);
    return true;
}

// --------------------------------------------------------------------------------

template<typename T>
T & aghDlist<T>::at(const int pos) const {

}

// --------------------------------------------------------------------------------

template<typename T>
int aghDlist<T>::size(void) const {
    return this->elements;
}

// --------------------------------------------------------------------------------

template<typename T>
bool aghDlist<T>::remove(const int pos) {
}

// --------------------------------------------------------------------------------

template<typename T>
void aghDlist<T>::clear(void) {
    
}
<commit_msg>Zdefiniowalem reszte metod aghDlist (remove, clear...)<commit_after>/**
 * @file aghDlist.h
 * @author <NAME>, <NAME>
 * @date 19|05|2016
 * @version 0.1
 * @brief Contains declaration and definition of aghDlist template class.
*/

// --------------------------------------------------------------------------------

#ifndef DATA_CONTAINER_AGHLIST_H
#define DATA_CONTAINER_AGHLIST_H

#include "aghContainer.h"
#include <iostream>

using namespace std;

/**
 * Class template to provide operations on double-sided list
*/
template<typename T>
class aghDlist :
         public aghContainer<T> {
public:
    aghDlist();

    aghDlist(const aghContainer<T> &);

    ~aghDlist();

    /**
     * Insert an element at specified position.
     * @param position number
     * @param new element
     */
    bool insert(const int, const T &);

    /**
     * Get element at specified position
     * @param position number
     * @return reference to the value
     */
    T & at(const int) const;

    /**
     * Get size of the container.
     * @return int size
     */
    int size(void) const;

    /**
     * Remove element at specified position.
     * @param position number
     * @return bool
     */
    bool remove(const int);

    /**
     * Remove all elements from the container.
     */
    void clear(void);

    /**
     * Assignment operator
     *
     * @param another vector
     * @return reference to the object
     */
    aghContainer<T> &operator=(const aghContainer<T> &);

private:
    template<typename Y>
    struct Node{
        Y value;
        Node<Y> * next;
        Node<Y> * prev;

        Node(Y value, Node* next = nullptr, Node* prev = nullptr) : value(value), next(next), prev(prev) {}
    };

    typedef Node<T> *listElem ;

    listElem head;
    listElem tail;

    unsigned int elements;

    listElem getNode(int) const;
};

// --------------------------------------------------------------------------------
// End of aghDlist declaration.
// --------------------------------------------------------------------------------

template<typename T>
aghDlist<T>::aghDlist() : head(nullptr), tail(nullptr), elements(0) {}

// --------------------------------------------------------------------------------

template<typename T>
aghDlist<T>::aghDlist(const aghContainer<T> &container) : head(nullptr), tail(nullptr) {
    this->copy(container);
}

// --------------------------------------------------------------------------------

template<typename T>
aghDlist<T>::~aghDlist() {
    this->clear();
}

// --------------------------------------------------------------------------------

template<typename T>
bool aghDlist<T>::insert(const int index, const T& value) {
    if (index > this->elements || index < 0)
        return false;

    listElem oldElem;
    listElem newElem;
    
    newElem = new Node<T>(value);
    
    if(index > 0) {
        oldElem = this->getNode(index-1);
        newElem -> prev = oldElem;
        newElem -> next = oldElem -> next;
        oldElem -> next = newElem;
        if(index != this->elements) 
            (newElem->next)->prev = newElem;
    }
    else {
        newElem -> next = this->head;
        this->head = newElem;
        if(index != this->elements)
            (newElem->next)->prev = newElem;
    }
    
    if(index != this->elements)
        (newElem->next)->prev = newElem;
    else
        this->tail = newElem;
    ++(this->elements);
    return true;
}

// --------------------------------------------------------------------------------

template<typename T>
T & aghDlist<T>::at(const int pos) const {
    return getNode(pos) -> value;
}

// --------------------------------------------------------------------------------

template<typename T>
int aghDlist<T>::size(void) const {
    return this->elements;
}

// --------------------------------------------------------------------------------

template<typename T>
bool aghDlist<T>::remove(const int pos) {
    if(index>=this->elements || index < 0)
        return false;

    listElem toRemove = this->getNode(pos);
    
    if(index > 0)
        (toRemove -> prev) -> next = toRemove -> next;
    else
        this -> head = toRemove -> next;
    
    if(index != this->elements-1)
        (toRemove -> next) -> prev = toRemove -> prev;
    else
        this -> tail = toRemove->prev;

    delete toRemove;
    --(this->elements);
    return true;  
    
}

// --------------------------------------------------------------------------------

template<typename T>
void aghDlist<T>::clear(void) {
    listElem current = this->head;
    listElem following;
    while(!current){
        following = current -> next;
        delete current;
        current = following;
    }
    this->head = nullptr;
    this->tail = nullptr;
    this-elements =0;
}

{'fraction_non_alphanumeric': 0.2941643059490085, 'fraction_numerical': 0.0036260623229461757, 'mean_word_length': 1.3605242043327093, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 134, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3766188', 'n_tokens_mistral': 2401, 'n_tokens_neox': 2349, 'n_words': 603}