Exemple #1
0
        //插入字符串到指定位置
        public bool Insert(int index, StringLink s)
        {
            if (s.IsEmpty())
            {
                Console.WriteLine("插入的字符串不能为空!");
                return(false);
            }

            char[] chars = s.ToChars();
            return(this.Insert(index, chars));
        }
        static void TestStringLink()
        {
            int        nodeLength = 3;
            StringLink s          = new StringLink(new char[] { 'a', 'f', 'g', 'g', 's', 'k' }, nodeLength);

            PrintStringLink(s, "串s为:");
            StringLink s2 = new StringLink(new char[] { '5', '2', '0', 'a' }, nodeLength);

            PrintStringLink(s2, "串s2为:");
            s.Concat(s2);
            StringLink s3 = new StringLink(new char[] { 'l', 'o', 'v', 'e' }, 20);

            PrintStringLink(s, "串链接s2后:");
            Console.WriteLine();

            Console.WriteLine("在串s中查找串s2:的位置为:" + s.Index(s2));
            s.Insert(5, new char[] { '1', '2', '8' });
            PrintStringLink(s, "在串s位置5插入128后:");
            s.Replace(s2, new StringLink(new char[] { 'l', 'u', 'o', '9' }, nodeLength));
            PrintStringLink(s, "替换串s中的s2为luo9后:");
            Console.WriteLine();

            Console.WriteLine("在算中查找gg的位置为:" + s.Index(new StringLink(new char[] { 'g', 'g' }, nodeLength)));
            s.Insert(9, s2);
            PrintStringLink(s, "在串s位置9前插入s2(520a)后:");
            s.Replace(new StringLink(new char[] { 'g', 'g' }, nodeLength), s2);
            PrintStringLink(s, "在串s中替换gg为s2(520a)后:");
            Console.WriteLine();

            PrintStringLink(s3, "串s3为:");
            s.Concat(s3);
            PrintStringLink(s, "串s链接串s3后:");
            s.Delete(2, 3);
            PrintStringLink(s, "删除串s位置为2长度为3的子串后:");
            s.Concat(s3);
            PrintStringLink(s, "串s链接串s3后:");
            s.Delete(1, 3);
            PrintStringLink(s, "删除串s位置为1长度为3的子串后:");
            s.Delete(6, 1);
            PrintStringLink(s, "删除串s位置为6长度为1的子串后:");
        }
Exemple #3
0
 //赋值为链串
 public void ValueTo(StringLink s)
 {
     char[] chars = s.ToChars();
     this.ValueTo(chars);
 }