Exemple #1
0
        /*
         *add node to the list
         */
        public void addNode(int value, int sub, bool mark)
        {
            Node temp = new Node();

            if (size == 0)
                head = tail = temp;
            else
            {
                tail.Next = temp;
                tail = temp;
            }
            size++;

            temp.Value = value;
            temp.Sub = sub;
            temp.Mark = mark;
        }
        /*
         * checkVaryByOneDigite checks if the two values vary by one digit.
         */
        private bool checkVaryByOneDigit(Node temp, Node ntemp)
        {
            int v, nv;

            int s, ns;

            int subt;

            v = temp.Value;

            nv = ntemp.Value;

            s = temp.Sub;

            ns = ntemp.Sub;

            subt = Math.Abs(v - nv);

            if (subt == 0 || s != ns)
            {
                return false;
            }
            else if (subt == 1)
            {
                if (v % 2 == 0)
                    return true;
                else
                    return false;
            }
            else if (checkPowerOfTwo(subt))
            {
                if (((v / subt) % 2) == 0)
                    return true;
                else
                    return false;
            }
            return
                false;

        }
        /************************************************************
         *  Quine–McCluskey algorithm
         *  Minimize is the function that minimize the truth table.
         *************************************************************
         */
        private TList minimize(TList mtable)
        {
            Node temp = new Node();

            Node ntemp = new Node();

            TList res = new TList();

            bool check_end = true;

            int subt = 0;

            temp = mtable.Head;

            while (temp != null)
            {
                ntemp = temp.Next;

                while (ntemp != null)
                {
                    subt = ntemp.Value - temp.Value;

                    if (checkVaryByOneDigit(temp, ntemp))
                    {
                        if ((res.Head == null) || (res.Tail.Value != temp.Value)
                                || (res.Tail.Sub != temp.Sub + subt))
                            res.addNode(temp.Value, temp.Sub + subt, false);

                        check_end = false;

                        temp.Mark = true;
                        ntemp.Mark = true;
                    }
                    ntemp = ntemp.Next;
                }
                if (!temp.Mark)
                    res.addNode(temp.Value, temp.Sub, false);
                temp = temp.Next;
            }
            if (check_end)
                return res;

            return minimize(res);
        }
Exemple #4
0
 public TList()
 {
     size = 0;
     head = null;
     tail = null;
 }
Exemple #5
0
 public Node()
 {
     value = -1;
     sub = 0;
     next = null;
     mark = false;
 }