void ReArrangeList(FrequencyLinkedListNode root) { FrequencyLinkedListNode first = root; FrequencyLinkedListNode second = root.next; while (second != null) { if (first.frequency == second.frequency) { ;// second = second.next; } else if (first.frequency < second.frequency) { int tempF = second.frequency; string tempW = second.word; second.frequency = first.frequency; second.word = first.word; first.frequency = tempF; first.word = tempW; first = second; } second = second.next; } }
FrequencyLinkedListNode GetWordCountsInLinkedList(List <string> strings) { FrequencyLinkedListNode prev = null; FrequencyLinkedListNode root = new FrequencyLinkedListNode(strings.First(), null, 1); foreach (string str in strings.Skip(1)) { FrequencyLinkedListNode cur = root; while (cur != null && cur.word != str) { prev = cur; cur = cur.next; } if (cur == null) { prev.next = new FrequencyLinkedListNode(str, null, 1); } else { cur.frequency++; //ReArrangeList(root); } } return(root); }
public FrequencyLinkedListNode(string word, FrequencyLinkedListNode next, int frequency) { this.word = word; this.next = next; this.frequency = frequency; }
public FrequencyLinkedListNode(string word, FrequencyLinkedListNode next, int frequency) { this.word = word; this.next = next; this.frequency = frequency; }
void ReArrangeList(FrequencyLinkedListNode root) { FrequencyLinkedListNode first = root; FrequencyLinkedListNode second = root.next; while (second != null) { if (first.frequency == second.frequency) ;// second = second.next; else if (first.frequency < second.frequency) { int tempF = second.frequency; string tempW = second.word; second.frequency = first.frequency; second.word = first.word; first.frequency = tempF; first.word = tempW; first = second; } second = second.next; } }
FrequencyLinkedListNode GetWordCountsInLinkedList(List<string> strings) { FrequencyLinkedListNode prev=null; FrequencyLinkedListNode root= new FrequencyLinkedListNode(strings.First(),null,1); foreach (string str in strings.Skip(1)) { FrequencyLinkedListNode cur = root; while (cur != null && cur.word != str) { prev = cur; cur = cur.next; } if (cur == null) { prev.next = new FrequencyLinkedListNode(str, null, 1); } else { cur.frequency++; //ReArrangeList(root); } } return root; }