func (s *SinglyLinkedList[T]) InsertAt(index int, value T) error {
	if index < 0 || index > s.count {
		return errIndexOutOfBounds
	}

	element := &SLLNode[T]{Value: value}
	if s.IsEmpty() {
		s.head = element
		s.tail = element
		s.count++
		element = nil
		return nil
	}

	if index == 0 {
		element.Next = s.head
		s.head = element
		s.count++
		element = nil
		return nil
	}

	if index == s.count {
		s.tail.Next = element
		s.tail = element
		s.count++
		element = nil
		return nil
	}

	current, err := s.getNode(index - 1)
	if err != nil {
		return err
	}

	element.Next = current.Next
	current.Next = element
	s.count++
	current = nil
	element = nil
	return nil
}
// InsertAt insert value at specific index in the list
InsertAt insert value at specific index in the list
// InsertAt insert value at specific index in the list
func (s *SinglyLinkedList[T]) InsertAt(index int, value T) error {
	if index < 0 || index > s.count {
		return errIndexOutOfBounds
	}
	element := &SLLNode[T]{Value: value}
	if s.IsEmpty() {
		s.head = element
		s.tail = element
		s.count++
		element = nil
		return nil
	}
	if index == 0 {
		element.Next = s.head
		s.head = element
		s.count++
		element = nil
		return nil
	}
	if index == s.count {
		s.tail.Next = element
		s.tail = element
		s.count++
		element = nil
		return nil
	}
	current, err := s.getNode(index - 1)
	if err != nil {
		return err
	}
	element.Next = current.Next
	current.Next = element
	s.count++
	current = nil
	element = nil
	return nil
}
func ( s * SinglyLinkedList [ T ] ) InsertAt ( index int , value T ) error { if index < 0 || index > s . count { return errIndexOutOfBounds } element := & SLLNode [ T ] { Value : value } if s . IsEmpty ( ) { s . head = element s . tail = element s . count ++ element = nil return nil } if index == 0 { element . Next = s . head s . head = element s . count ++ element = nil return nil } if index == s . count { s . tail . Next = element s . tail = element s . count ++ element = nil return nil } current , err := s . getNode ( index - 1 ) if err != nil { return err } element . Next = current . Next current . Next = element s . count ++ current = nil element = nil return nil }
InsertAt insert value at specific index in the list
InsertAt insert value at specific index in the list