/// <summary> /// Update Rank /// </summary> /// <param name="list"></param> static void updateRankInList(ref LinkedList <WordStructre> list) { int Rank = 1; LinkedListNode <WordStructre> currentNode = list.First; while (currentNode != null) { WordStructre node = currentNode.Value; node.Rank = Rank++; currentNode.Value = node; currentNode = currentNode.Next; } }
/// <summary> /// concatenateLinkedList two linkedlist /// </summary> /// <param name="parentList"></param> /// <param name="SecondList"></param> static void concatenateLinkedList(ref LinkedList <WordStructre> parentList, LinkedList <WordStructre> SecondList) { foreach (WordStructre secondList in SecondList) { LinkedListNode <WordStructre> currentNode = parentList.First; while (currentNode != null) { bool loopBreak = false; #region only case when we add less level word to the list currentNode.Value.word.Length > word.Length if (currentNode.Value.word.Length > secondList.word.Length) { parentList.AddBefore(currentNode, new WordStructre { word = secondList.word, Occurrence = 1 }); loopBreak = true; break; } #endregion #region If the same level word if (currentNode.Value.word.Length == secondList.word.Length) { // If mor than one Occurrence of a same word if (CompareWord.Equal == StrcmpNext(currentNode.Value.word, secondList.word)) { WordStructre updatedNode = currentNode.Value; updatedNode.Occurrence = updatedNode.Occurrence + secondList.Occurrence; currentNode.Value = updatedNode; loopBreak = true; break; } //if new word is Small we can simply add new in the begin Since it a sorted list if (CompareWord.NewWordSmallThanCurrentNodeAddBefore == StrcmpNext(currentNode.Value.word, secondList.word)) { { parentList.AddBefore(currentNode, new WordStructre { word = secondList.word, Occurrence = 1 }); loopBreak = true; } } //Add New is Large so add after the current node else { if (currentNode.Next != null) { //Check for the next node in the list,add if next node word is small the word if (CompareWord.NewWordSmallThanCurrentNodeAddBefore == StrcmpNext(currentNode.Next.Value.word, secondList.word)) { parentList.AddAfter(currentNode, new WordStructre { word = secondList.word, Occurrence = 1 }); loopBreak = true; } // Add next level word for frist time else if (CompareWord.CountLargerThan == StrcmpNext(currentNode.Next.Value.word, secondList.word)) { parentList.AddAfter(currentNode, new WordStructre { word = secondList.word, Occurrence = 1 }); loopBreak = true; } } else { parentList.AddAfter(currentNode, new WordStructre { word = secondList.word, Occurrence = 1 }); loopBreak = true; } } } #endregion #region Add next level word if current node next is null else { if (currentNode.Next == null) { parentList.AddAfter(currentNode, new WordStructre { word = secondList.word, Occurrence = 1 }); loopBreak = true; } } #endregion if (loopBreak) { break; } currentNode = currentNode.Next; //Reach the requested Rank } } }