public static ListOfDigits GetSummOfLists(ListOfDigits a, ListOfDigits b) { var a_node = a.YoungerNode; var b_node = b.YoungerNode; ListNode biggest_node = null; ListOfDigits result = new ListOfDigits(); var res_node = result.YoungerNode; int added_sum = 0; while (!(a_node is null) && !(b_node is null)) { int tmp_sum = a_node.Value + b_node.Value + added_sum; res_node.Value = tmp_sum % 10; added_sum = tmp_sum / 10; ListNode elderNode = new ListNode(); res_node.ElderNode = elderNode; elderNode.YoungerNode = res_node; res_node = elderNode; a_node = a_node.ElderNode; b_node = b_node.ElderNode; } if (!(a_node is null)) { biggest_node = a_node; }
public IActionResult OnPost() { if (First >= 0 && Second >= 0) { SummOfNumbers = First + Second; ListOfDigits list1 = new ListOfDigits(First); ListOfDigits list2 = new ListOfDigits(Second); SummOfLists = ListOfDigitsCalculator.GetSummOfLists(list1, list2).ToString(); } return(Page()); }