zoukankan      html  css  js  c++  java
  • 递归、遍历、冒泡

    1.一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。
    public class TuZi
        {
            public int TZ(int x)
            {
                if (x == 1 || x == 2)
                {
                    return 1;
                }
                else
                {
                    return TZ(x - 1) + TZ(x - 2);
                }
            }
        }
        class Program
        {
            static void Main(string[] args)
            {
                TuZi a = new TuZi();
                Console.WriteLine(a.TZ(12));
            }
        }


    2.遍历页面上所有的textbox页面并将它赋值为string.empty?
    foreach (System.Windows.Forms.Control item in this.Controls)
                {
                    if (item is System.Windows.Forms.TextBox)
                    {
                        System.Windows.Forms.TextBox tb = (System.Windows.Forms.TextBox)item;
                        tb.Text = string.Empty;
                    }
                }
    control类是所有控件的基类

    3.实现一个冒泡排序算法
    int[] arr = { 10, 29, 30, 40, 5 };
                for (int i = arr.Length; i >= 2;i-- )
                {
                    for (int j = 0; j <i - 1;j++ )
                    {
                        if (arr[j] < arr[j + 1])
                        {
                            int temp = arr[j + 1];
                            arr[j + 1] = arr[j];
                            arr[j] = temp;                  
                        }              
                    }   
                }
                foreach (int item in arr)
                {
                    Console.Write(item+" ");
                    
                }
                Console.Read();

  • 相关阅读:
    消息队列 资源不足,无法执行操作
    内存级的缓存实际上引用
    Vs 2013 单步调试 .net framework 中遇到的问题
    Win7总是显示“软件应用无法兼容”的解决方法
    Win10系统文件受损怎么办
    教你win10系统如何一键修复系统
    Win10专业版如何提升游戏流畅度
    win7电脑任务管理器被停用如何解决
    win7系统移动硬盘打不开解决方法
    Java之集合(五)LinkedList
  • 原文地址:https://www.cnblogs.com/zxhome/p/4130679.html
Copyright © 2011-2022 走看看