#1 Added operator overload, [], to Linked List
This commit is contained in:
		@@ -9,7 +9,7 @@ namespace Datastructures {
 | 
			
		||||
		LinkedList();
 | 
			
		||||
		LinkedList(T value);
 | 
			
		||||
		~LinkedList();
 | 
			
		||||
		T operator[](int index);
 | 
			
		||||
		T& operator[](int index);
 | 
			
		||||
		void append(T value);
 | 
			
		||||
		bool insert(T value, int index);
 | 
			
		||||
		bool remove(int index);
 | 
			
		||||
@@ -43,6 +43,12 @@ namespace Datastructures {
 | 
			
		||||
	template <typename T>
 | 
			
		||||
	LinkedList<T>::~LinkedList() {}
 | 
			
		||||
 | 
			
		||||
	template <typename T> 
 | 
			
		||||
	T& LinkedList<T>::operator[](int index) {
 | 
			
		||||
		//Return the value from a given index. (Will return null pointer if out of range)
 | 
			
		||||
		return this->getIndex(index)->value;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	template <typename T>
 | 
			
		||||
	void LinkedList<T>::append(T value) {
 | 
			
		||||
		mCount++;
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@ int main() {
 | 
			
		||||
	list.append(200);
 | 
			
		||||
	list.insert(20, 2);
 | 
			
		||||
	std::cout << list.count() << std::endl; //3
 | 
			
		||||
	std::cout << list[0] << list[1] << list[2] << std::endl; //520020
 | 
			
		||||
	list.remove(0);
 | 
			
		||||
	int x = list.find(10);
 | 
			
		||||
	std::cout << list.count() << std::endl; //2
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user