C 基础
递归链表反序
void Invert(struct node *p)
{
if(p->next==NULL) return;
if(p->next->next!=0)
Invert(p->next);
p->next->next = p;
p->next = 0;
}
两种方法判断是否有相同字串,一是效率最高的,二是最节省内存的.
int fn1(const char *str)
{
unsigned char *p = ( unsigned char *)str;
int a[255]={0};
for( ; *p != '\0'; p++ )
if( ++a[*p] == 2 ) return 1;
return 0;
}
int fn2(const char *str)
{
const char *p1, *p2;
if (*str == '\0')
return 0;
for (p1 = str; *p1 != ''; p1++)
for (p2 = p1 + 1; *p2 !=''; p2++)
if (*p1 == *p2)
return 1;
return 0;
}
一句话判断是否是2的幂次: #define Is2n(a) ( a > 0 ) && ( ( ( ~a + 0x01 ) &a ) == a )
int a[3];
a[0]=0; a[1]=1; a[2]=2;
int *p, *q;
p=a;
q=&a[2];
则
a[q-p]=?
当然是
2
。
高低位交换:
int test;
test = ( test<<8 & 0xFF00 ) | ( test>>8 & 0x00FF );
)
找一个数1的个数:
内存换速度
char one[256]={0,1,1,2,1,2,……} // 此为 0-255 每个数中 1 的个数
int func(int n){
for(int i=0;n>0;n>>=8)
i+=one[n&255];
return i;
}
2)&优化
int func(int n){
int count=0;
while(n>0){
n&=(n-1);
count++;
}
return count;
}
相关文档:
/*
coder: ACboy
date: 2010-3-14
result: 1A
description: UVa 327 Evaluating Simple C Expressions
*/
#include <iostream>
#include <algorithm>
using namespace std;
struct Node {
char name;
int value;
int lastValue;
int pos;
};
int cmp(const Node & a, const Node &a ......
1.首先是获得linux内核源码,好像是废话,下载地址如下:ftp://ftp.kernel.org/pub/linux/kernel/v2.6/下载:
linux-2.6.16.22.tar.bz2 patch-2.6.22.6.bz2
上面一步需要说明的是一般而言,linux内核的各个补丁文件是根据某个linux内核的版本号来作的patch。
将上面的两个压缩文件解压:
tar jxvf linux-2.6.22.ta ......
可以将XML文件的树(只有一个顶层节点).于是理所当然的可以用树作为XML的一种存储结构.
我将在这里用C++实现对简单的XML文件的解析.
1.选择存储结构:
树型数据结构有多种存储方式,我将用"孩子兄弟表示法",定义如下:
typedef struct CSNode
{
int subNodes;
string data;
string name;
struct CSNode *fi ......
本试题仅用于考查C++/C程序员的基本编程技能。内容限于C++/C常用语法,不涉及数据结构、算法以及深奥的语法。考试成绩能反映出考生的编程质量以及对C++/C的理解程度,但不能反映考生的智力和软件开发能力。
笔试时间90分钟。请考生认真答题,切勿轻视。
一、请填写BOOL , float, 指针变量 与“零值”比较的 i ......
注:请允许我转载您的佳作
在windows上开发能够在linux上编译的C代码,我查了查有2个软件可以实现,一个是Cygwin,一个是mingw。其中cygwin是一个windows上linux环境的模拟工具,他提供了很多linux工具的windows实现版本,例如vi,emacs等等,当然也包括GCC。使用mingw的好处就是编译过的程序直接就可以跑了,而cygwin则需 ......