Exemplo n.º 1
0
        /// <summary>
        /// Hàm tạo danh sách liên kết với các node kiểu int, từ chuỗi nhập
        /// </summary>
        /// <param name="strInput">Chuỗi nhập vào</param>
        public ListSN(string strInput = null)
        {
            intCount = 0;
            bool zeroInHead = true;

            if (strInput != null)
            {
                // Chỉ số
                int signIndex = 0;

                while (strInput[signIndex] == '0')
                {
                    signIndex++;
                }

                int i = strInput.Length - 1;

                try
                {
                    while (i >= signIndex)
                    {
                        AddNext(Int32.Parse(new string(strInput[i], 1)));
                        i--;
                    }
                }
                catch
                {
                    throw new Exception("Co loi xay ra khi, vui long kiem tra du lieu nhap!!!");
                }

            }
            else
                nodeCurrent = null;
        }
Exemplo n.º 2
0
 public void AddNext(int intNode)
 {
     if (nodeCurrent != null)
     {
         nodeCurrent.NodeNext = new Node(nodeCurrent, null, intNode);
         nodeCurrent = nodeCurrent.NodeNext;
     }
     else
     {
         nodeCurrent = new Node(null, null, intNode);
     }
     intCount++;
 }
Exemplo n.º 3
0
 public Node(Node _prev, Node _next, int _val)
 {
     try
     {
         nodePrev = _prev;
         nodeNext = _next;
         intVal = _val;
     }
     catch
     {
         throw new Exception("Co loi xay ra khi tao node, vui long kiem tra du lieu nhap!!!");
     }
 }
Exemplo n.º 4
0
        public ListSN(string strInput = null)
        {
            intCount = 0;

            if (strInput != null)
            {
                int i = strInput.Length - 1;
                try
                {
                    while (i >= 0)
                    {
                        AddNext(Int32.Parse(new string(strInput[i], 1)));
                        i--;
                    }
                }
                catch
                {
                    throw new Exception("Co loi xay ra khi, vui long kiem tra du lieu nhap!!!");
                }

            }
            else
                nodeCurrent = null;
        }
Exemplo n.º 5
0
        private int intVal; // giá trị của node hiện tại

        #endregion Fields

        #region Constructors

        public Node(Node _prev, Node _next, int _val)
        {
            nodePrev = _prev;
            nodeNext = _next;
            intVal = _val;
        }
Exemplo n.º 6
0
        public Node ToFirst()
        {
            if (nodeCurrent.NodePrev == null)
                return nodeCurrent;

            while (nodeCurrent.NodePrev != null)
                nodeCurrent = nodeCurrent.NodePrev;

            return nodeCurrent;
        }
Exemplo n.º 7
0
        public Node ToNext()
        {
            if (nodeCurrent != null)
            {
                if (nodeCurrent.NodeNext == null)
                    return (NodeCurrent = null);
                else
                {
                    nodeCurrent = nodeCurrent.NodeNext;

                    return nodeCurrent;
                }
            }
            else
                return (NodeCurrent = null);
        }