ivanseidel / LinkedList

🔗 A fully implemented LinkedList made to work with general Microcontrollers and Arduino projects
MIT License
350 stars 118 forks source link

Added swap(index, index1) method #65

Open davidefa opened 1 year ago

davidefa commented 1 year ago

Added swap method as follow:

    /*
        Swap objects at index and index1;
    */
    virtual bool swap(int index, int index1);
template<typename T>
bool LinkedList<T>::swap(int index, int index1){
    // Check if index position is in bounds
    if(index < 0 || index >= _size)
        return false;
    if(index1 < 0 || index1 >= _size)
        return false;

    T _t = getNode(index)->data;
    getNode(index)->data = getNode(index1)->data;
    getNode(index1)->data = _t;
    return true;
}