public INodeContent CreateContent(ILinkedNode parent) { var content = new NodeContent(); Root.Add(content); content.SetParentNode(parent); return(content); }
private LinkedNode CheckNode(ILinkedNode <T> node) { if (node is LinkedNode impl && ReferenceEquals(this, impl.List)) { return(impl); } throw new InvalidOperationException("Node does not belong to this list."); }
public IEnumerator <ILinkedNode <T> > GetEnumerator() { ILinkedNode <T> current = _front; while (current != null) { yield return(current); current = current.NextNode; } }
public List <int> Go() { SinglyLinkedListImpl imp = new SinglyLinkedListImpl(); ILinkedNode <int> rootfirst = new LinkedNode <int>(); ILinkedNode <int> rootsec = new LinkedNode <int>(); imp.FillLinkedList(rootfirst, true); imp.FillLinkedListS(rootsec, true); //Merge(rootfirst, rootsec); ILinkedNode <int> merged = MergeLists(rootfirst, rootsec); return(new List <int>()); }
private void rev(ILinkedNode <int> root) { ILinkedNode <int> prev = null; ILinkedNode <int> cell = root; while (cell != null) { ILinkedNode <int> Next = cell.Next; cell.Next = prev; prev = cell; cell = Next; } }
private void Reverse(ILinkedNode <int> root) { if (root == null) { return; } ILinkedNode <int> cur = root; ILinkedNode <int> prev = null; while (cur != null) { ILinkedNode <int> next = cur.Next; cur.Next = prev; prev = cur; cur = next; } }
//private ILinkedNode<int> SortRecurs(ILinkedNode<int> root, int cmpr) //{ // if (root == null) return null; // // if (root.Next == null) return root; // ILinkedNode<int> maxNode = null; // if (root.Data.CompareTo(root.Next.Data) >= 0) // { // maxNode = root; // } // else // { // maxNode = root.Next; // } // int min = Math.Min(root.Data, cmpr); // ILinkedNode<int> node = SortRecurs() //} private void Sort(ILinkedNode <int> root) { ILinkedNode <int> cell = root; ILinkedNode <int> sorted = new LinkedNode <int>(); while (cell != null) { ILinkedNode <int> next = cell.Next; cell = cell.Next; ILinkedNode <int> after_me = sorted; while (after_me != null && after_me.Data < next.Data) { after_me = after_me.Next; } next.Next = after_me; after_me.Next = next; } }
/// <summary> /// More Efficient solution /// </summary> /// <param name="rootF"></param> /// <param name="rootS"></param> /// <returns></returns> ILinkedNode <int> MergeLists(ILinkedNode <int> rootF, ILinkedNode <int> rootS) { if (rootF == null) { return(rootS); } if (rootS == null) { return(rootF); } int res = rootF.CompareTo(rootS.Data); if (res < 0) { rootF.Next = MergeLists(rootF.Next, rootS); return(rootF); } rootS.Next = MergeLists(rootS.Next, rootF); return(rootS); }
void Merge(ILinkedNode <int> rootF, ILinkedNode <int> rootS) { ILinkedNode <int> merged = null; ILinkedNode <int> lastmerged = new LinkedNode <int>(); ILinkedNode <int> first = rootF; ILinkedNode <int> second = rootS; while (first != null || second != null) { if (first == null) { lastmerged = addValToGener(lastmerged, second); second = second.Next; continue; } if (second == null) { lastmerged = addValToGener(lastmerged, first); first = first.Next; continue; } while (second != null && first != null) { int res = first.CompareTo(second.Data); if (res >= 0) { ILinkedNode <int> nexts = second.Next; lastmerged = addValToGener(lastmerged, second); second = nexts; } else if (res < 0) { ILinkedNode <int> nextf = first.Next; lastmerged = addValToGener(lastmerged, first); first = nextf; } } } }
public void FillLinkedListS(ILinkedNode <int> root, bool needToBeSorted = false) { Random r = new Random(); int[] arr = new int[4]; arr = arr.Select(x => r.Next(10000)).ToArray(); if (needToBeSorted) { Array.Sort(arr); } ILinkedNode <int> next = root; for (int i = 0; i < arr.Length; i++) { next.Data = arr[i]; if (i != arr.Length - 1) { next.Next = new LinkedNode <int>(); next = next.Next; } } }
public static bool HasLeft(this ILinkedNode _this) { return(_this.Left != null); }
public void SetParentNode(ILinkedNode parent) { Parent = ( Cell )parent; }
public void Remove(ILinkedNode <T> node) { var impl = CheckNode(node); impl.RemoveFromList(); }
public void AddBefore(ILinkedNode <T> node, T item) { var impl = CheckNode(node); AddBefore(impl, item); }
public void AddAfter(ILinkedNode <T> node, T item) { var impl = CheckNode(node); AddAfter(impl, item); }
public Task <Cid> PutAsync(ILinkedNode data, string contentType, string multiHash = MultiHash.DefaultAlgorithmName, CancellationToken cancel = default(CancellationToken)) { throw new NotImplementedException(); }
public static bool HasRight(this ILinkedNode _this) { return(_this.Right != null); }
public Task <Cid> PutAsync(ILinkedNode data, string contentType, string multiHash = "sha2-256", CancellationToken cancel = default(CancellationToken)) { throw new NotImplementedException(); }
static ILinkedNode <int> addValToGener(ILinkedNode <int> lastAddedCell, ILinkedNode <int> toAdded1) { lastAddedCell.Next = toAdded1; return(toAdded1); }