Archive for 五月, 2013

Android ListView 正在加载 异步载入数据 CursorLoader 例子

还记得这篇文章吗?Android ListView 最基本的用法,使用SimpleCursorAdapter 。 附例子。我在使用的时候,载入大量数据时,开始会很卡,滑动倒是不会卡,就是因为开始载入是用一条sql语句查询所有数据。Android中遇到这样的问题一般用线程来执行。看了下Android 4.0 Contacts的载入方式,它非常流畅。发现它用了CursorLoader ,这里用它来做一个小小的例子。左边的是刚开始的效果,你也可以改成一个dialog罩住不让用户用。右边的是载入完成的样子,设计到联系人隐私,画了下。 CursorLoader 还是蛮好用的不过它Added in API level 11,Android 3.0才能用。Android2.3即以下都不能用,比较遗憾。 哦,对了,下面这应用别忘记加上读取联系人权限。                    &nb […]

C++ Queue Example Rearranging RailRoad Cars 火车车厢重排问题

Before in article C++ Stack Example Rearranging RailRoad Cars 火车车厢重排问题 we use three stacks to solve the “Rearranging RailRoad Cars” problem. In this article, we will use two queues to solve the problem.       The Whole Code // RailRoadQueue.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <q […]

C++ Stack Example Rearranging RailRoad Cars 火车车厢重排问题

  Look at figure 1. The railroad cars  in the “Input track” is not sorted. We need them in a sorted way  in “Output track” like cars in figure2.     There are three holding tracks we can use to rearranging roailroad cars. A picture is worth than a thousand words, so look at the gif picture below. You can see how the process acts.         & […]

The Towers of Hanoi recursion 汉诺塔 C++

What is Towers of Hanoi ?   Figure1 shows an tower of hanoi setup with three discs on the first pole. Note that all the discs are a different size. The a < b < c.   The Rules The goal is move all discs from first pole to the last pole. There are three rules: 1. A large disc can never be placed on top of a small disc. 2. You can only move one disc at a time 3. You can move discs on […]