一、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. mysql编码不统一形成的错误

    错误提示:[Err]1267 - Illegal mix of collations(utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) ...

  2. GPRS的短信和打电话功能

    短信功能: 发短信设置文本格式就可以了:但收短信可能收到的是乱码,需要编写解码程序才可以: 关于打电话单片机复位功能: 首先要建立黑白名单制度过滤手机号,只运行白名单的手机对的单片机打电话:其它的不响 ...

  3. android actionbar viewpager 实现类微信主界面布局

    1 Activity public class MainActivity extends FragmentActivity { private ViewPager pager; private Act ...

  4. Java Hashtable 源码(JDK8)

    记录了HashMap也来看看Hashtable吧,最近打算换份实习,所以想看看书回顾一下,不然就快记不得了.....囧啊囧啊,记性太差怎么破??? Hashtable里面的一些变量: Entry< ...

  5. poj 3601 Tower of Hanoi

    Tower of Hanoi Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 1853   Accepted: 635 De ...

  6. python中lambda,map,reduce,filter,zip函数

    函数式编程 函数式编程(Functional Programming)或者函数程序设计,又称泛函编程,是一种编程范型,它将计算机运算视为数学上的函数计算,并且避免使用程序状态以及易变对象.简单来讲,函 ...

  7. Python对列表中字典元素排序

    问题起源 json对象a,b a = '{"ROAD": [{"id": 123}, {"name": "no1"}]} ...

  8. React.js 小书 Lesson24 - PropTypes 和组件参数验证

    作者:胡子大哈 原文链接:http://huziketang.com/books/react/lesson24 转载请注明出处,保留原文链接和作者信息. 我们来了到了一个非常尴尬的章节,很多初学的朋友 ...

  9. Codeforces 671 A——Recycling Bottles——————【思维题】

     Recycling Bottles time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  10. java gc 随记

    gc为garbage collection的缩写,中文翻译为垃圾回收.垃圾为不在使用的实例.变量,回收为释放垃圾所占用的内存空间. 学习过的C语言.C++语言,是没有垃圾回收机制的,因此需要软件工程师 ...