Skip to content

Added swap(index, index1) method #65

Description

@davidefa

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;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions