I'm learning C# and I've made a recursive insert-method for a linked list:
public static int recursiveInsert(ref int value, ref MyLinkedList list) {
if (list == null)
return new MyLinkedList(value, null);
else {
list.next = recursiveInsert(ref int value, ref list.next);
return list;
}
}
How can I modify this method to make the recursive call look like this:
recursiveInsert(value, ref list.next)
instead of:
list.next = recursiveInsert(ref int value, ref list.next);
returnstatements don't all match up.valueas the return value of the function. Also, this will cause a Stackoverflow exception since you never stop recursing.