易截截图软件、单文件、免安装、纯绿色、仅160KB

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;
}


相关文档:

Linux 下编译C程序

GCC 支持了许多不同的语言,包括 C、C++、Ada、Fortran、Objective C,Perl、Python 和 Ruby,甚至还有Java。
  Linux 内核和许多其他自由软件以及开放源码应用程序都是用 C 语言编写并使用 GCC 编译的。
  编译C++程序:
  -c 只编译不连接
  g++ file1 -c -o file1.o
  g++ file2 -c -o file2.o
  g++ f ......

用c读取XML文件

 
  可以将XML文件的树(只有一个顶层节点).于是理所当然的可以用树作为XML的一种存储结构.
我将在这里用C++实现对简单的XML文件的解析.
1.选择存储结构:
树型数据结构有多种存储方式,我将用"孩子兄弟表示法",定义如下:
typedef struct CSNode
{
int subNodes;
string data;
string name;
struct CSNode *fi ......

linux 常用c函数


opendir(打开目录)
相关函数
open,readdir,closedir,rewinddir,seekdir,telldir,scandir
表头文件
#include<sys/types.h>
#include<dirent.h>
定义函数
DIR * opendir(const char * name);
函数说明
opendir()用来打开参数name指定的目录,并返回DIR*形态的目录流,和open()类似,接下 ......

更高效率的A^B mod C bird

#include <stdio.h>
#define LL unsigned long long int

inline LL mod(LL a,LL b)
{
while (a>=b)
a-=b;
return a;
}
//a*b mod c
inline LL MulAndMod(LL a, LL shl_b,LL c)
{
LL val,pre;
pre = mod(a,c);
val = 0;
......

C: 面向对象(2)

演示如何用C实现继承,重载之类的玩艺儿。VC++6.0编译通过。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef class
        #define class struct
#endif
#ifndef private
        #define privat ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号