Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 public FrequencyLinkedListNode(string word, FrequencyLinkedListNode next, int frequency)
 {
     this.word      = word;
     this.next      = next;
     this.frequency = frequency;
 }
Ejemplo n.º 4
0
 public FrequencyLinkedListNode(string word, FrequencyLinkedListNode next, int frequency)
 {
     this.word = word;
     this.next = next;
     this.frequency = frequency;
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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;
        }