private static bool CompareChains(Chain chain1, Chain chain2) { if ((chain1 == null) && (chain2 == null)) return false; if ((chain1 != null) && (chain2 == null)) return true; if ((chain1 == null) && (chain2 != null)) return false; if (chain1.Length > chain2.Length) return true; if (chain1.Length < chain2.Length) return false; if (chain1.FirstElement > chain2.FirstElement) return true; if (chain1.FirstElement < chain2.FirstElement) return false; if (chain1.FirstElementDisplacement < chain2.FirstElementDisplacement) return true; return false; }
public static void FindChain() { Chain etalonChain = null; Chain currentChain = null; for (ulong i = 0; i < (ulong)dataArray.Length; i++) { if (dataArray[i] != 0) { ulong displacement = i; if (currentChain == null) { currentChain = new Chain(dataArray[i], displacement); } else if (dataArray[i] > currentChain.LastElement.GetValueOrDefault()) { currentChain.AddElement(dataArray[i], displacement); } else { if (CompareChains(currentChain, etalonChain)) { etalonChain = currentChain; } currentChain = new Chain(dataArray[i], displacement); } } } if (currentChain != null) { if (CompareChains(currentChain, etalonChain)) etalonChain = currentChain; } Console.Write("\rProgress: 100% "); if (etalonChain != null) RecieveChainHelper.RecieveTheChain(etalonChain); else RecieveChainHelper.RecieveTheChain(null); }