Updated Index checking bound on Linked List
This commit is contained in:
		@@ -45,17 +45,22 @@ namespace C_.Datastructures
 | 
			
		||||
        public T? this[int i]
 | 
			
		||||
        {
 | 
			
		||||
            get {
 | 
			
		||||
                Node<T> node = Traverse(i); 
 | 
			
		||||
                //Check Range
 | 
			
		||||
                if (i >= Count) throw new System.Exception("Error! Index out of Bounds");
 | 
			
		||||
 | 
			
		||||
                //Return Value
 | 
			
		||||
                Node<T>? node = Traverse(i); 
 | 
			
		||||
                if (node != null) return node.Value;
 | 
			
		||||
                return default(T);
 | 
			
		||||
            }
 | 
			
		||||
            set
 | 
			
		||||
            {
 | 
			
		||||
                if (i < Count)
 | 
			
		||||
                {
 | 
			
		||||
                    Node<T> node = Traverse(i);
 | 
			
		||||
                    node.Value = value;
 | 
			
		||||
                }
 | 
			
		||||
                //Check Range
 | 
			
		||||
                if (i >= Count) throw new System.Exception("Error! Index out of Bounds");
 | 
			
		||||
 | 
			
		||||
                //Change Value
 | 
			
		||||
                Node<T>? node = Traverse(i);
 | 
			
		||||
                node!.Value = value;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user