2013年11月28日

为什么使用do{}while(0)来进行宏定义

摘要: 最近发现很多代码在进行宏定义的时候使用喜欢使用#define MACRO_NAME(para) do{macro content}while(0)的格式,总结了以下几个原因:1,空的宏定义避免warning:#define foo() do{}while(0)2,存在一个独立的block,可以用来进行变量定义,进行比较复杂的实现。3,如果出现在判断语句过后的宏,这样可以保证作为一个整体来是实现:#define foo(x) \action1(); \action2();在以下情况下:if(NULL == pPointer) foo();就会出现action1和action2不会同时被执行的.. 阅读全文

posted @ 2013-11-28 16:08 DerDeath 阅读(470) 评论(0) 推荐(0) 编辑

2013年11月1日

单向链表的反转

摘要: #include #include #include using namespace std;class ListNode {public: ListNode *next; int data;};ListNode* reverse(ListNode * head) { ListNode *pCur, *pPrev, *pNext; pPrev = NULL; pCur = head; while (pCur != NULL) { pNext = pCur->next; pCur->next = pPrev; pPrev = pCur; pCur = pNext; } return 阅读全文

posted @ 2013-11-01 20:02 DerDeath 阅读(470) 评论(0) 推荐(0) 编辑

2012年11月29日

Dijkstra算法[小结]

摘要: Dijkstra(迪杰斯特拉)算法是典型的单源最短路径算法,用于计算一个节点到其他所有节点的最短路径。主要特点是以起始点为中心向外层层扩展,直到扩展到终点为止。Dijkstra算法是很有代表性的最短路径算法,在很多专业课程中都作为基本内容有详细的介绍,如数据结构,图论,运筹学等等。Dijkstra一般的表述通常有两种方式,一种用永久和临时标号方式,一种是用OPEN, CLOSE表的方式,这里均采用永久和临时标号的方式。注意该算法要求图中不存在负权边。算法步骤如下: 1. 初使时令 S={V0},T={其余顶点},T中顶点对应的距离值 若存在<V0,Vi>,d(V0,Vi)为< 阅读全文

posted @ 2012-11-29 14:37 DerDeath 阅读(327) 评论(0) 推荐(0) 编辑

2012年8月28日

pat 1019 General Palindromic Number

摘要: A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.Although palindromic numbers are most often considered in the decimal system, the concept of palind 阅读全文

posted @ 2012-08-28 20:56 DerDeath 阅读(720) 评论(0) 推荐(0) 编辑

PAT 1020 Tree Traversals

摘要: 1020. Tree Traversals (25)时间限制 400 ms内存限制 32000 kB代码长度限制 16000 B判题程序 StandardSuppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding bi... 阅读全文

posted @ 2012-08-28 13:19 DerDeath 阅读(1146) 评论(0) 推荐(0) 编辑

2011年12月2日

判断Email 地址是否合法的正则表达式

摘要: "^[0-9a-zA-Z_-]+(\\.[0-9a-zA-Z_-]+)*@[a-zA-Z0-9_-]+(\\.{1}[a-zA-Z0-9_-]+)*\\.{1}[a-zA-Z]{2,4}$" 阅读全文

posted @ 2011-12-02 14:50 DerDeath 阅读(176) 评论(0) 推荐(0) 编辑

2011年9月6日

android 从xml创建控件

摘要: android从xml创建控件根据xml创建view (res/layout 这个文件夹中的play_cartoon_exit.xml)View viewxml=getLayoutInflater().inflate(R.layout.play_cartoon_exit,null);在非activity时可以:LayoutInflater inflater = (LayoutInflater)context.getSystemService( Context.LAYOUT_INFLATER_SERVICE);View viewxml = inflater.inflate(R.layout.pl 阅读全文

posted @ 2011-09-06 10:25 DerDeath 阅读(503) 评论(0) 推荐(0) 编辑

2011年8月31日

Java - 数字与罗马数字转换

摘要: 1 public String arabicToRoman (int arabic){ 2 String roman = null; 3 switch(arabic){ 4 case 1:{ 5 roman = "I"; 6 break; 7 } 8 case 2:{ 9 roman = "II";10 break;11 }12 ... 阅读全文

posted @ 2011-08-31 15:56 DerDeath 阅读(628) 评论(0) 推荐(0) 编辑

2011年8月9日

Android RotateImageView 可旋转ImageView

摘要: 1 package com.droidhen.game.layout; 2 3 import android.content.Context; 4 import android.graphics.Bitmap; 5 import android.graphics.Bitmap.Config; 6 import android.graphics.Canvas; 7 import android.graphics.Paint; 8 import android.graphics.PaintFlagsDrawFilter; 9 import android.graphics.Rect; 10 im. 阅读全文

posted @ 2011-08-09 18:02 DerDeath 阅读(10445) 评论(0) 推荐(0) 编辑

2011年8月4日

Android ListView 分割线的长度

摘要: 是listitem宽度 - 4个像素。左右对齐为2个像素 阅读全文

posted @ 2011-08-04 12:56 DerDeath 阅读(512) 评论(0) 推荐(0) 编辑

导航

"); }); },1000); });