refactor
This commit is contained in:
@@ -39,6 +39,7 @@ a = a - b;
|
|||||||
最终示例代码:
|
最终示例代码:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
//反转
|
||||||
void _reverse(char *start,char *end){
|
void _reverse(char *start,char *end){
|
||||||
if ((start == NULL) || (end == NULL)) return;
|
if ((start == NULL) || (end == NULL)) return;
|
||||||
while(start < end){
|
while(start < end){
|
||||||
@@ -55,11 +56,15 @@ char *revert_by_word(char *source){
|
|||||||
char *end = source;
|
char *end = source;
|
||||||
char *start = source;
|
char *start = source;
|
||||||
if (source == NULL) return NULL;
|
if (source == NULL) return NULL;
|
||||||
|
|
||||||
|
//end指针挪动到尾部
|
||||||
while (*end != '\0') end++;
|
while (*end != '\0') end++;
|
||||||
end--;
|
end--;
|
||||||
|
|
||||||
|
//先全部反转
|
||||||
_reverse(start,end);
|
_reverse(start,end);
|
||||||
|
|
||||||
|
//按单词反转
|
||||||
start=end=source;
|
start=end=source;
|
||||||
while(*start != '\0'){
|
while(*start != '\0'){
|
||||||
if (*start == ' '){
|
if (*start == ' '){
|
||||||
@@ -94,7 +99,9 @@ char *left_rotate(char *str,int offset){
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
思路: 我们可以abcdef分成两部分,ab和cdef,内部逆序以后,整体再次逆序,就可以得到想要的结果了,也就是跟上面的问题是同样的问题。
|
思路: 我们可以abcdef分成两部分,ab和cdef,内部逆序以后,整体再次逆序,就可以得到想要的结果了。
|
||||||
|
也就是跟上面的问题是同样的问题。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 判断字符串是否是回文
|
## 判断字符串是否是回文
|
||||||
|
|||||||
+2
-2
@@ -51,7 +51,7 @@ int main(int argc, char const *argv[])
|
|||||||
char *test = "how are you ?";
|
char *test = "how are you ?";
|
||||||
printf("%s\n",_revert_by_word(test));
|
printf("%s\n",_revert_by_word(test));
|
||||||
|
|
||||||
//char *test = "I am a student.";
|
test = "I am a student.";
|
||||||
//printf("%s\n",revert_by_word(test));
|
printf("%s\n",revert_by_word(test));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -264,7 +264,7 @@ void compress(char *src){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int count = 1;
|
int count = 1;
|
||||||
char *back=src,forward=src+1;
|
char *back=src,*forward=src+1;
|
||||||
|
|
||||||
while(*forward){
|
while(*forward){
|
||||||
|
|
||||||
+2
-4
@@ -3,11 +3,9 @@
|
|||||||
二叉查找树变成双向链表
|
二叉查找树变成双向链表
|
||||||
*/
|
*/
|
||||||
|
|
||||||
strcut BSTreeNode{
|
typedef struct BSTreeNode{
|
||||||
|
|
||||||
int m_nValue;
|
int m_nValue;
|
||||||
BSTreeNode *m_pLeft,m_pRight;
|
struct BSTreeNode *m_pLeft, *m_pRight;
|
||||||
|
|
||||||
}BSTree;
|
}BSTree;
|
||||||
|
|
||||||
void convertDoubleLinks(BSTree *root){
|
void convertDoubleLinks(BSTree *root){
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
char ch = 'a';
|
char ch = 'a';
|
||||||
foobar1(33, ch);
|
foobar1();
|
||||||
foobar2();
|
foobar2();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
#include "c13-1.c"
|
#include "c13-1.c"
|
||||||
|
|
||||||
extern int *arr;
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
arr[1] = 100;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
-10
@@ -8,17 +8,12 @@
|
|||||||
#define test_file_path "./ip.txt"
|
#define test_file_path "./ip.txt"
|
||||||
#define ip_count 100000000 //随机1亿个IP
|
#define ip_count 100000000 //随机1亿个IP
|
||||||
#define tmp_file_count 32
|
#define tmp_file_count 32
|
||||||
|
|
||||||
#define mem_count 128*1024*1028 //128MB个IP空间
|
#define mem_count 128*1024*1028 //128MB个IP空间
|
||||||
|
|
||||||
|
|
||||||
int hash(unsigned i){
|
int hash(unsigned i){
|
||||||
|
|
||||||
return i>>27;
|
return i>>27;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|
||||||
|
|
||||||
@@ -52,9 +47,6 @@ int main(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//开始读测试数据IP,按IP,映射到32个文件中
|
//开始读测试数据IP,按IP,映射到32个文件中
|
||||||
FILE *testfd = fopen(test_file_path2,"r");
|
FILE *testfd = fopen(test_file_path2,"r");
|
||||||
if (!testfd)
|
if (!testfd)
|
||||||
@@ -76,8 +68,6 @@ int main(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 依次读入每个文件并统计, hash_map 统计每个区间段的最大IP
|
// 依次读入每个文件并统计, hash_map 统计每个区间段的最大IP
|
||||||
int hash_map[mem_count];
|
int hash_map[mem_count];
|
||||||
int max_ip;
|
int max_ip;
|
||||||
Reference in New Issue
Block a user