zoukankan      html  css  js  c++  java
  • LearnHowToThink

    一、BubbleSort and XListview
    1、BubbleSort
    (1)analysis
    traverse、compare、exchange、cycle、optimize strategy
    loop outside times n-1
    loop inside times n-i-1 it reduces 1 next cycle
    (2)code:
    void BubbleSort(int arr[],int n)
    {
        int i,j,temp;
        for(i=0;i<n-1;i++)
        {
            for(j=0;j<n-i-1;j++)
            {
                if(arr[j]>arr[j+1])
                {
                    temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                }
            }
        }
    }
    (3)price:o(n*n)
    (4)optimize strategy
    no exchange,then break:
    void BubbleSort2(int arr[],int n)
    {
        int i,j,temp,flag;
        for(i=0;i<n-1;i++)
        {
            flag=0;
            for(j=0;j<n-i-1;j++)
            {
                if(arr[j]>arr[j+1])
                {
                    temp=arr[j];
                    arr[j]=arr[j+1];
                    arr[j+1]=temp;
                    flag=1;
                }
            }
            if(!flag)
            {
                break;
            }
        }
    }
    2、ChooseSort
    (1)analysis
    choose the min element every time,and exchange it with the first(move one by one) element。
    (2)code
    void ChooseSort(int arr[],int n)
    {
        int i,j,temp,min;
        for(i=0;i<n-1;i++)
        {
            min=i;
            for(j=i+1;j<n;j++)
            {
                if(arr[j]<arr[min])
                {
                    min=j;
                }
            }
            if(i!=min)
            {
                temp=arr[i];
                arr[i]=arr[min];
                arr[min]=temp;
            }
        }
    }
    (3)price:o(n*n)
    (4)supplementary
    Of course,you can also choose the max element to exchange。
     
    3、InsertSort
    analysis:
         Insert a number into a list which is already ordered。traverse the list from the tail to the head until  it is larger than current and find where to place the number。
    code:
    void InsertSort(int a[],int n)
    {
        int i,j;
        for(i=0;i<n-1;i++)
        {
            int m=a[i+1];
            for(j=i+1;j>0;j--)
            {
                if(m<a[j-1])
                {
                    a[j]=a[j-1];
                }
                else
                {
                    break;//这一句非常关键
                }
            }
            a[j]=m;
        }
    }
     
    二、XListView
    1、layout、arrow、textview,header and footer is different
    2、three conditions,normal、ready、refreshing,different condition has different layout,vary from one to one.
    3、event handle
    when trigger the event and what to do.
    4、XlistViewHeader XListViewFooter XListView XListViewActivity
    related api:LinearLayout、ListView、activity、OnScrollListener
  • 相关阅读:
    Auto.js脚本程序控制手机APP
    jemter运行报错,{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"00-d0eeccb9ae68f44798713724724a4353-4623dc713e44b34c-00"
    解决ModuleNotFoundError: No module named 'pip'问题
    'vue-cli-service' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
    vue配置
    创建分支,提交代码
    Navicat 12.1安装与破解之Navicat Keygen Patch使用方法
    vue--04
    Maven 打包程序如何使用可在外部修改的配置文件
    Vue 2.6 中部分引入 TypeScript 的方法
  • 原文地址:https://www.cnblogs.com/nannanITeye/p/3832290.html
Copyright © 2011-2022 走看看