示例#1
0
        public DST()

        {
            root = null;

            current = null;
        }
示例#2
0
        public void Insert3(string keyword)

        {
            Node3 newNode = new Node3();

            newNode.Key = keyword;

            if (root == null)
            {
                root = newNode;
            }

            else

            {
                Node3 current = root;

                Node3 parent;

                parent = current;

                int indexBytes = 0;

                byte[] arrayBits = new byte[keyword.Length * 8];

                byte[] arrayBytes = Encoding.GetEncoding("koi8-r").GetBytes(keyword);

                for (indexBytes = 0; indexBytes < arrayBytes.Length; indexBytes++)

                {
                    arrayBits[indexBytes * 8] = (byte)(((int)arrayBytes[indexBytes] >> 7) & 0x01);

                    arrayBits[indexBytes * 8 + 1] = (byte)(((int)arrayBytes[indexBytes] >> 6) & 0x01);

                    arrayBits[indexBytes * 8 + 2] = (byte)(((int)arrayBytes[indexBytes] >> 5) & 0x01);

                    arrayBits[indexBytes * 8 + 3] = (byte)(((int)arrayBytes[indexBytes] >> 4) & 0x01);

                    arrayBits[indexBytes * 8 + 4] = (byte)(((int)arrayBytes[indexBytes] >> 3) & 0x01);

                    arrayBits[indexBytes * 8 + 5] = (byte)(((int)arrayBytes[indexBytes] >> 2) & 0x01);

                    arrayBits[indexBytes * 8 + 6] = (byte)(((int)arrayBytes[indexBytes] >> 1) & 0x01);

                    arrayBits[indexBytes * 8 + 7] = (byte)((int)arrayBytes[indexBytes] & 0x01);
                }

                for (int n = 3; n < arrayBits.Length; n++)

                {
                    parent = current;

                    if (current.Key == keyword)
                    {
                        break;
                    }

                    else

                    {
                        if (arrayBits[n] == 0)

                        {
                            current = current.Left;

                            if (current == null)

                            {
                                parent.Left = newNode;

                                parent.Left.Key = keyword;

                                break;
                            }

                            else if (current != null)
                            {
                                continue;
                            }

                            else if (current.Key == keyword)
                            {
                                break;
                            }
                        }

                        else if (arrayBits[n] == 1)

                        {
                            current = current.Right;

                            if (current == null)

                            {
                                parent.Right = newNode;

                                parent.Right.Key = keyword;

                                break;
                            }

                            else if (current != null)
                            {
                                continue;
                            }

                            else if (current.Key == keyword)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
示例#3
0
        public int Delete3(string delWord)

        {
            Node3 current = root;

            if (current.Key == delWord)

            {
                current.Key = null;

                return(1);
            }

            else

            {
                byte[] arrayBits = new byte[delWord.Length * 8];

                byte[] arrayBytes = Encoding.GetEncoding("koi8-r").GetBytes(delWord);

                for (int indexBytes = 0; indexBytes < arrayBytes.Length; indexBytes++)

                {
                    arrayBits[indexBytes * 8] = (byte)(((int)arrayBytes[indexBytes] >> 7) & 0x01);

                    arrayBits[indexBytes * 8 + 1] = (byte)(((int)arrayBytes[indexBytes] >> 6) & 0x01);

                    arrayBits[indexBytes * 8 + 2] = (byte)(((int)arrayBytes[indexBytes] >> 5) & 0x01);

                    arrayBits[indexBytes * 8 + 3] = (byte)(((int)arrayBytes[indexBytes] >> 4) & 0x01);

                    arrayBits[indexBytes * 8 + 4] = (byte)(((int)arrayBytes[indexBytes] >> 3) & 0x01);

                    arrayBits[indexBytes * 8 + 5] = (byte)(((int)arrayBytes[indexBytes] >> 2) & 0x01);

                    arrayBits[indexBytes * 8 + 6] = (byte)(((int)arrayBytes[indexBytes] >> 1) & 0x01);

                    arrayBits[indexBytes * 8 + 7] = (byte)((int)arrayBytes[indexBytes] & 0x01);
                }

                for (int n = 3; n < arrayBits.Length; n++)

                {
                    if (arrayBits[n] == 0)

                    {
                        current = current.Left;

                        if (current != null)

                        {
                            if (current.Key == delWord)

                            {
                                current.Key = null;

                                return(1);
                            }

                            else
                            {
                                continue;
                            }
                        }

                        else
                        {
                            return(0);
                        }
                    }

                    else if (arrayBits[n] == 1)

                    {
                        current = current.Right;

                        if (current != null)

                        {
                            if (current.Key == delWord)

                            {
                                current.Key = null;

                                return(1);
                            }

                            else
                            {
                                continue;
                            }
                        }

                        else
                        {
                            return(0);
                        }
                    }

                    else
                    {
                        return(0);
                    }
                }

                return(0);
            }
        }