一、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

LearnHowToThink的更多相关文章

随机推荐

  1. python学习15-序列化(转载)

    序列化是指把内存里的数据类型转换成字符串,以使其能存储到硬盘或通过网络传输到远程,因为硬盘和网络传输时只能接受bytes 一.pickle 把python对象写入到文件中的一种解决方案,但是写入到文件 ...

  2. (转)Linux-HA开源软件Heartbeat(配置篇)

    原文:http://ixdba.blog.51cto.com/2895551/548625 http://gzsamlee.blog.51cto.com/9976612/1828870 Linux-H ...

  3. Anaconda环境变量配置问题解决

    (右键)我的电脑==>属性==>高级系统设置==>环境变量==>Path 按照下图添加: 总共4个,如果出现“此环境变量太大...”,删除或者缩短其他环境变量地址. 然后重新打 ...

  4. android TCP 和 UDP总结(转)

    之前写过一些关于TCP和UDP数据传输的代码,比如使用TCP传输音视频数据包,P2P打洞中使用UDP等.写好之后就直接丢下了,没有总结下都.最近准备找工作,再拿来温习下. 1.还是先说点啥 暂时把自己 ...

  5. 【Css】一个简单的图片库

    今天做一个简单的图片库! 其实这个在w3school教程里介绍得很好了,不过看到什么,自己动手做一次,记得也深刻不是. 我们分几步来走: 第一步:先写一个坯子. <html> <he ...

  6. 《C++ Primer》〓〓〓〓〓〓〓〓〓〓【第七章】

    7.5.1 构造函数初始化列表 如果成员是const.引用,或者属于某种未提供默认构造函数的类类型,我们必须通过构造函数初始值列表为这些成员提供初值. 成员的初始化顺序与他们在类定义中的出现顺序一致. ...

  7. HDU 5700——区间交——————【线段树+枚举】

    区间交 Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...

  8. vue2.0的虚拟DOM渲染

    1.为什么需要虚拟DOM 前面我们从零开始写了一个简单的类Vue框架(文章链接),其中的模板解析和渲染是通过Compile函数来完成的,采用了文档碎片代替了直接对页面中DOM元素的操作,在完成数据的更 ...

  9. online contest

    http://atcoder.jp/contest https://nanti.jisuanke.com/contest http://codeforces.com/ https://www.nowc ...

  10. WeUI logo专为微信设计的 UI 库 WeUI

    http://www.oschina.net/p/weui?fromerr=FnwHyWAb http://weui.github.io/weui/