
C/C++语言
luofaliang
因为坚信,所以等待。
展开
-
删除特定字符串(c语言)
#include #include #include #include void Delete(char *str,char *str2){ assert(str!=NULL); int i=0,j=0,k=0; int len=strlen(str2); do { if( str[i] != str2[k] ) str[j++]=str[i]; else原创 2013-03-24 14:03:51 · 1027 阅读 · 0 评论 -
快速排序(递归和非递归)
#includeusing namespace std;int Partion(int *a, int l, int h){int p = a[l];while (l=high)return;int q = Partion(a,low,high);quick_sort(a,low,q-1);quick_sort(a,q+1,high);}*/// 非递归法void quick_sort(int原创 2013-09-27 18:17:46 · 502 阅读 · 0 评论 -
去掉代码前的行号(行号范围 1~999)
/* 该程序用于去除代码前的序号,如在网上复制的代码每行都有序号时,序号范围适用于 1~999 */#include void main(){ char dir1[40] = {0}, dir2[40] = {0},ch[3] = {0}; FILE *fR = NULL,*fW = NULL; printf("源路径:"); gets(dir1); fR = fopen(dir原创 2013-05-29 13:10:30 · 613 阅读 · 0 评论 -
函数模板简单两例(c++)
例一:#includeusing namespace std;templatevoid display(T1 x, T2 y){ cout<<x<<" "<<y<<endl;}int main(){ char c='A'; char str[]="Hello world!"; int n=10; float x=1.5; double z=3.1415926;原创 2013-05-29 14:52:27 · 357 阅读 · 0 评论 -
合并排序
#include #include #include //合并排序的合并程序他合并数组nData中位置为[nP,nM) 和[nM,nR).这个是更接近标准的思路 bool MergeStandard(int nData[], int nP, int nM, int nR) { int n1 = nM - nP; //第一个合并数据的长度 int n转载 2013-05-26 22:39:16 · 386 阅读 · 0 评论 -
求质数(C++语言)
/*刚一个同学来问我求质数的问题,我想这个问题很简单,就说百度一大堆,搜了一下,看见很多都是错误的或者即使正确效率依然很低,但要自己立马写出来也不是1+1的事情,于是就试着写了下,自我感觉不错,因为我觉得我写的这个运算效率还是比较高的。*/#include #include #include using namespace std;void main(){ int max,len=2原创 2013-04-10 20:35:41 · 633 阅读 · 0 评论 -
链表的基础知识
//一直觉得学计算机归根到底都是算法。试着回忆了一下链表的知识//单向链表结构typedef struct node{ int info; struct node *next; // 再加类似这样的一条语句就是双向链表了}node;//单向链表首部插入结点node *push_front(node *head,int info){ node* p=(node *)malloc原创 2013-04-10 20:55:43 · 472 阅读 · 0 评论 -
截取一句话中的单词(C语言)
#include #include int GetWordNum(char *str){ assert(str!=NULL); int num=0; char *pChar=(char*)str; while (*pChar!='\0') { char *pBegin=pChar; //每个单词的头指针 while (*pChar!=' ' && *pChar+原创 2013-03-24 21:12:27 · 1097 阅读 · 0 评论 -
二进制转换成字符串
#include using namespace std;void reserve(char a[]){ int count = 0, temp = 0,max = 0; char *p = a; //指向末尾 while(*p++!='\0') { count++; } int len = max = (count+1)/4-1; int *b= new int[le原创 2013-10-19 19:19:12 · 699 阅读 · 0 评论