摘要: 1 #include 2 #include 3 #include 4 using namespace std; 5 6 void TransformExpr(char *oldexpr,char *newexpr) 7 { 8 stack s; 9 int i=0; 10 int j=0; 11 while(oldexpr[i] != '\0') 12... 阅读全文
posted @ 2018-11-24 19:48 执著的追求 阅读(169) 评论(0) 推荐(0) 编辑
摘要: 题目一: [cpp] view plaincopy void GetMemory( char *p ) { p = (char *) malloc( 100 ); } void Test( void ) { char *str = NULL; GetMemory( str ); strcpy( str, "hello world" ); printf( str ... 阅读全文
posted @ 2018-11-24 19:48 执著的追求 阅读(633) 评论(0) 推荐(0) 编辑
摘要: 1 int N = 3; 2 int V = 5; 3 int C[4] = {0,1,2,3}; 4 int W[4] = {0,60,100,120}; 5 int f[N][V]; 6 //memset(f,0,sizeof(int)*N*V); 7 for(int i=0;i (f[i-1][j-C[i]]+W[i])? f[i-1][j]:(f[i-1][j-C[i]]+... 阅读全文
posted @ 2018-11-24 19:47 执著的追求 阅读(193) 评论(0) 推荐(0) 编辑
摘要: 1 namespace AStuff{ 2 template 3 class A 4 { 5 public: 6 void swap(A *other) 7 { 8 using std::swap; 9 swap(pImpl,other.plmpl); 10 } 11 private: 12 AImpl *pImpl; 13 }; 14 template 15 void sw... 阅读全文
posted @ 2018-11-24 19:46 执著的追求 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 1 void Permutation(char* pStr, char* pBegin) 2 { 3 assert(pStr && pBegin); 4 5 if(*pBegin == '\0') 6 printf("%s\n",pStr); 7 else 8 { 9 for(char* pCh = pBegin; *pCh != '\0'; pCh++) 10 { 11 s... 阅读全文
posted @ 2018-11-24 19:45 执著的追求 阅读(139) 评论(0) 推荐(0) 编辑
摘要: 1 int matrix[MAX][MAX]; 2 void PrintMatrix(int x,int y,int start,int n) 3 { 4 if(n==0) 5 return ; 6 if(n==1) 7 { 8 matrix[x][y] = start; 9 return ; 10 } 11 int i,j; 12 for(j=y;jy;j--) 17 mat... 阅读全文
posted @ 2018-11-24 19:45 执著的追求 阅读(315) 评论(0) 推荐(0) 编辑
摘要: 1 union 2 { 3 short s; 4 char c[sizeof(short)]; 5 }test; 6 7 int main() 8 { 9 //method 1 10 int a = 0x12345678; 11 if(*((char *)&a) == 0x12) 12 printf("big-endian\n"); 13 else 14 printf("l... 阅读全文
posted @ 2018-11-24 19:44 执著的追求 阅读(104) 评论(0) 推荐(0) 编辑
摘要: int LCS(char *a,char *b) { if(a==NULL || b==NULL) return 0; int len_a = strlen(a); int len_b = strlen(b); int f[M][N]; for(int i=1;i f[i-1][j] ? f[i][j-1]:f[i-1][j]); } } return f[i-1][j-1]; } 阅读全文
posted @ 2018-11-24 19:42 执著的追求 阅读(82) 评论(0) 推荐(0) 编辑
摘要: 1 void Calculate(int a) 2 { 3 int pa = a; 4 int count = 0; 5 int b[20] = {0}; 6 7 //将pa按位存储到数组b 8 while(pa > 0) 9 { 10 b[count++] = pa%10; 11 pa = pa/10; 12 } 13 bool flag = tr... 阅读全文
posted @ 2018-11-24 19:42 执著的追求 阅读(330) 评论(0) 推荐(0) 编辑
摘要: 1 char *MyStrcpy(char *des,const char *src) 2 { 3 assert(des != NULL && src != NULL); 4 char *pstr = des; 5 while((*pstr++ = *src++)!= '\0'); 6 return des; 7 } 8 9 char *MyStrcat(char *des,... 阅读全文
posted @ 2018-11-24 19:41 执著的追求 阅读(103) 评论(0) 推荐(0) 编辑
摘要: void MaxLengthCore(char *cur,char *pre,int *max,int cursum) { if(*cur == '\0') return ; if(pre !=NULL && *cur == *pre) { ++cursum; if(cursum > *max) *max = cursum; pre = cur; MaxLengthCore(++cur,pre,... 阅读全文
posted @ 2018-11-24 19:40 执著的追求 阅读(274) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #define NUM 3 int n=0; pthread_mutex_t t_mutex; pthread_cond_t t_cond; void *Execute(void *p) { int i=0; int para = (int)p; for(;i<10;i++) { pthread_mutex_lock(&t_mutex);... 阅读全文
posted @ 2018-11-24 19:39 执著的追求 阅读(297) 评论(0) 推荐(0) 编辑
摘要: 输入:{5,3,4,8,6,7} 输出:4即{3,4,6,7} 阅读全文
posted @ 2018-11-24 19:38 执著的追求 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 1 class MyQueue 2 { 3 public: 4 MyQueue(); 5 bool Get(int *&p); 6 bool Put(int a); 7 int GetLength(); 8 private: 9 struct Node * rear; 10 struct Node * front; 11 int length; 12 }; 13 14 MyQ... 阅读全文
posted @ 2018-11-24 19:37 执著的追求 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 1 struct QNode 2 { 3 struct Node *front; 4 struct Node *tail; 5 unsigned int len; 6 }; 7 8 9 struct Qlist 10 { 11 struct QNode *qlist; 12 pthread_mutex_t m_... 阅读全文
posted @ 2018-11-24 19:36 执著的追求 阅读(176) 评论(0) 推荐(0) 编辑
摘要: 1 void Rotate(char *start,char *end) 2 { 3 if(start == NULL || end == NULL) return ; 4 while(start<end) 5 { 6 char temp = *start; 7 *start = *end; 8 *end = temp; 9 --end;++start; 10 } 11 } 1... 阅读全文
posted @ 2018-11-24 19:34 执著的追求 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 1 push(const T& element) 2 { 3 if(queue1.size()>0)//如果queue1不为空则往queue1中插入元素 4 queue1.push(element); 5 else if(queue2.size()>0)//如果queue2不为空则往queue2中插入元素 6 queue2.push(element); 7 else//如果两个队列... 阅读全文
posted @ 2018-11-24 19:34 执著的追求 阅读(91) 评论(0) 推荐(0) 编辑
摘要: 单链表的快排 快排的非递归实现 阅读全文
posted @ 2018-11-24 19:33 执著的追求 阅读(567) 评论(0) 推荐(0) 编辑
摘要: KMP算法 BF算法 阅读全文
posted @ 2018-11-24 19:31 执著的追求 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 1 void AdjustHeap(int *a,int n,int cur) 2 { 3 int i,tmp; 4 for(i=2*cur+1;ia[i]) 9 break; 10 tmp = a[cur]; 11 a[cur] = a[i]; 12 a[i] = tmp; 13 cur = i; 14 } 15 } 16 17 void HeapSort(int *a,int n... 阅读全文
posted @ 2018-11-24 19:29 执著的追求 阅读(98) 评论(0) 推荐(0) 编辑