zoukankan      html  css  js  c++  java
  • 关于字符串、递归、冒泡排序的一些操作

                a = textBoxX1.Text.ToString();
                b = textBoxX2.Text.ToString();
                d = a.Contains(b).ToString();//判断a中是否包含b 返回 true false
                MessageBox.Show (d);
    
                //分组
                string[] b1 = a.Split('*');//通过*号分割字符串a
                c = b1[0];//通过索引位置取值
    
                //判断并返回坐标
                int index = a.IndexOf("*");//判断a中是否包含*,返回*的索引位置
                if (index > -1)
                {
                    c = a.Substring(0, index - 1);//截取字符串  0,*索引号-1
                }

    一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现

            //\//\//\//\递归//\//\//\//\
            public static int Foo(int i)
            {
                if (i <= 0)
                    return 0;
                else if (i > 0 && i <= 2)
                    return 1;
                else
                    return Foo(i - 1) + Foo(i - 2);
            }
    
            private void buttonX2_Click(object sender, EventArgs e)
            {
                int i = int.Parse(textBoxX3.Text.ToString());
                labelX1.Text = Foo(i).ToString();
            }

     

    冒泡排序+数组类型转换

            //\//\//\//\//冒泡排序\//\//\//\//\//
            private void MaoPao(int[] a)
            {
                int[] array = a;
                int temp = 0;
                for (int i = 0; i < array.Length - 1; i++)
                {
                    for (int j = i + 1; j < array.Length; j++)
                    {
                        if (array[j] < array[i])
                        {
                            temp = array[i];
                            array[i] = array[j];
                            array[j] = temp;
                        }
                    }
                }
            }
            //\//\//\//\数组类型转换//\//\//\
            public static int StrToInt(string str)
            {
                return int.Parse(str);
            }
    
            private void buttonX3_Click(object sender, EventArgs e)
            {
                string[] arrs =textBoxX4.Text.ToString().Split(',');
                int[] arri = Array.ConvertAll(arrs, new Converter<string, int>(StrToInt));
                MaoPao(arri);
                for (int i = 0; i <=arri.Length-1; i++)
                {
                    textBoxX5.Text += arri[i]+" ";                
                }
            }
  • 相关阅读:
    Linux工具之man手册彩色页设置
    使用bakefile编译C工程代码
    学会使用简单的 MySQL 常用操作
    Mysql数据库的通用安装方法
    从Mysql数据库中导入导出表结构
    CentOS下安装MySQL数据库
    lua函数调用
    innodb记录延迟删除对于其它DB操作的影响
    从apache派生cgi工作路径看软链接
    两台主机互为网关是否会像打乒乓球一样一直互发
  • 原文地址:https://www.cnblogs.com/zhizhuo-1991/p/5565951.html
Copyright © 2011-2022 走看看