Example #1
0
        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;
            }
        }
Example #2
0
        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);
        }
Example #3
0
 public FrequencyLinkedListNode(string word, FrequencyLinkedListNode next, int frequency)
 {
     this.word      = word;
     this.next      = next;
     this.frequency = frequency;
 }
Example #4
0
 public FrequencyLinkedListNode(string word, FrequencyLinkedListNode next, int frequency)
 {
     this.word = word;
     this.next = next;
     this.frequency = frequency;
 }
Example #5
0
        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;
            }
        }
Example #6
0
        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;
        }