public int CompareTo(object obj) { Minian second = (Minian)obj; if (this.Height != second.Height) { return(this.Height.CompareTo(second.Height)); } else { return(this.Weight.CompareTo(second.Weight)); } }
private void LongestSubsequenceExistingForGivenIndex(Minian[] minians, List <Minian>[] solution, int currIdx) { // validations if (currIdx < 0 || currIdx >= minians.Length) { return; } Minian currElement = minians[currIdx]; List <Minian> bestSeqence = null; // iterate from 0 to curridx-1 in the solutions list, and find the bestSequence so far, such that seq.LastElement < currElement for (int i = 0; i < currIdx; i++) { Minian last = solution[i] == null ? new Minian { Height = 0, Weight = 0 } : solution[i].LastOrDefault(); if (last.Weight < currElement.Weight) { bestSeqence = FindBestSequence(bestSeqence, solution[i], currElement); } } // if found a bestSequence, // append currElement to it. // add this squence to the solutions list. List <Minian> newSeq = null; if (bestSeqence != null) { newSeq = new List <Minian>(bestSeqence); newSeq.Add(currElement); } else { newSeq = new List <Minian>(); newSeq.Add(currElement); } solution[currIdx] = newSeq; // call LongestSubsequenceExistingForGivenIndex with currIdx+1 LongestSubsequenceExistingForGivenIndex(minians, solution, currIdx + 1); }
static void Main(string[] args) { var x = Strings.StringToNumber("-123.45"); x = Strings.StringToNumber("-123"); x = Strings.StringToNumber("123"); x = Strings.StringToNumber("123.45"); Test_FindMAxSubmatrix(); TestKadanesAlgo(); //// Median Finding across two sorted arrays int[] M = new int[] { 0, 1, 8 }; int[] N = new int[] { 2, 4, 9, 12 }; MiscQuestions misc = new MiscQuestions(); int median = misc.FindMedianOfTwoSortedArrays(M, N); M = new int[] { 1, 2, 4, 8, 9, 10 }; N = new int[] { 3, 5, 6, 7 }; median = misc.FindMedianOfTwoSortedArrays(M, N); /////BitTitan B.BitTitanQuestion q = new B.BitTitanQuestion(); B.Node root = new B.Node('R'); root.Children = new B.Node[3]; root.Children[0] = new B.Node('A'); root.Children[1] = new B.Node('B'); root.Children[2] = new B.Node('C'); B.Node A = root.Children[0]; A.Children = new B.Node[2]; A.Children[0] = new B.Node('D'); A.Children[1] = new B.Node('E'); B.Node BB = root.Children[1]; BB.Children = new B.Node[3]; BB.Children[0] = new B.Node('F'); BB.Children[1] = new B.Node('G'); BB.Children[2] = new B.Node('H'); B.Node C = root.Children[2]; C.Children = new B.Node[] { new B.Node('I') }; q.SetRightLink(root); //MyLinkedList l = new MyLinkedList(3); //l.InsertHead(4); //l.InsertAfter(5, 4); //bool has = l.HasDuplicate("abcgdjgA"); //has = l.HasDuplicate("abcgdjA"); //string str = l.RemoveDuplicate("abcgdjA"); TestMyDictionary(); // get nth unique char char c = Strings.NthUniqueChar("This is a string", 2); c = Strings.NthUniqueChar("This is a string", 5); c = Strings.NthUniqueChar("This is a string", 0); Minian[] m = new Minian[5] { new Minian { Height = 70, Weight = 80 }, new Minian { Height = 72, Weight = 70 }, new Minian { Height = 79, Weight = 64 }, new Minian { Height = 60, Weight = 64 }, new Minian { Height = 70, Weight = 69 } }; LongestSubsequence ls = new LongestSubsequence(); ls.FindLongestSubsequenceOfMinians(m); }
private List <Minian> FindBestSequence(List <Minian> bestSeqenceSoFar, List <Minian> sequenceForGivenIndex_i, Minian m) { if (bestSeqenceSoFar == null) { return(sequenceForGivenIndex_i); } else if (sequenceForGivenIndex_i == null) { return(bestSeqenceSoFar); } else { return(bestSeqenceSoFar.Count > sequenceForGivenIndex_i.Count ? bestSeqenceSoFar : sequenceForGivenIndex_i); } }