diff --git a/9 Algorithms Job Interview/1 字符串.md b/9 Algorithms Job Interview/1 字符串.md index c77468f..30960ee 100644 --- a/9 Algorithms Job Interview/1 字符串.md +++ b/9 Algorithms Job Interview/1 字符串.md @@ -39,6 +39,7 @@ a = a - b; 最终示例代码: ``` +//反转 void _reverse(char *start,char *end){ if ((start == NULL) || (end == NULL)) return; while(start < end){ @@ -55,11 +56,15 @@ char *revert_by_word(char *source){ char *end = source; char *start = source; if (source == NULL) return NULL; + + //end指针挪动到尾部 while (*end != '\0') end++; end--; + //先全部反转 _reverse(start,end); + //按单词反转 start=end=source; while(*start != '\0'){ if (*start == ' '){ @@ -94,7 +99,9 @@ char *left_rotate(char *str,int offset){ } ``` -思路: 我们可以abcdef分成两部分,ab和cdef,内部逆序以后,整体再次逆序,就可以得到想要的结果了,也就是跟上面的问题是同样的问题。 +思路: 我们可以abcdef分成两部分,ab和cdef,内部逆序以后,整体再次逆序,就可以得到想要的结果了。 +也就是跟上面的问题是同样的问题。 + ## 判断字符串是否是回文 diff --git a/9 Algorithms Job Interview/测试代码/1 string/char_first_appear_once.c b/9 Algorithms Job Interview/codes/1 string/char_first_appear_once.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/1 string/char_first_appear_once.c rename to 9 Algorithms Job Interview/codes/1 string/char_first_appear_once.c diff --git a/9 Algorithms Job Interview/测试代码/1 string/proc.c b/9 Algorithms Job Interview/codes/1 string/proc.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/1 string/proc.c rename to 9 Algorithms Job Interview/codes/1 string/proc.c diff --git a/9 Algorithms Job Interview/测试代码/1 string/replce_blank.c b/9 Algorithms Job Interview/codes/1 string/replce_blank.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/1 string/replce_blank.c rename to 9 Algorithms Job Interview/codes/1 string/replce_blank.c diff --git a/9 Algorithms Job Interview/测试代码/1 string/revert_by_word.c b/9 Algorithms Job Interview/codes/1 string/revert_by_word.c similarity index 92% rename from 9 Algorithms Job Interview/测试代码/1 string/revert_by_word.c rename to 9 Algorithms Job Interview/codes/1 string/revert_by_word.c index da95e3a..ea113b1 100644 --- a/9 Algorithms Job Interview/测试代码/1 string/revert_by_word.c +++ b/9 Algorithms Job Interview/codes/1 string/revert_by_word.c @@ -51,7 +51,7 @@ int main(int argc, char const *argv[]) char *test = "how are you ?"; printf("%s\n",_revert_by_word(test)); - //char *test = "I am a student."; - //printf("%s\n",revert_by_word(test)); + test = "I am a student."; + printf("%s\n",revert_by_word(test)); return 0; } diff --git a/9 Algorithms Job Interview/测试代码/1 string/string.c b/9 Algorithms Job Interview/codes/1 string/string.c similarity index 99% rename from 9 Algorithms Job Interview/测试代码/1 string/string.c rename to 9 Algorithms Job Interview/codes/1 string/string.c index 88fe732..9d778b2 100644 --- a/9 Algorithms Job Interview/测试代码/1 string/string.c +++ b/9 Algorithms Job Interview/codes/1 string/string.c @@ -264,7 +264,7 @@ void compress(char *src){ } int count = 1; - char *back=src,forward=src+1; + char *back=src,*forward=src+1; while(*forward){ diff --git a/9 Algorithms Job Interview/测试代码/10.c b/9 Algorithms Job Interview/codes/10.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/10.c rename to 9 Algorithms Job Interview/codes/10.c diff --git a/9 Algorithms Job Interview/测试代码/12.c b/9 Algorithms Job Interview/codes/12.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/12.c rename to 9 Algorithms Job Interview/codes/12.c diff --git a/9 Algorithms Job Interview/测试代码/20.c b/9 Algorithms Job Interview/codes/20.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/20.c rename to 9 Algorithms Job Interview/codes/20.c diff --git a/9 Algorithms Job Interview/测试代码/21.c b/9 Algorithms Job Interview/codes/21.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/21.c rename to 9 Algorithms Job Interview/codes/21.c diff --git a/9 Algorithms Job Interview/测试代码/22.c b/9 Algorithms Job Interview/codes/22.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/22.c rename to 9 Algorithms Job Interview/codes/22.c diff --git a/9 Algorithms Job Interview/测试代码/23.c b/9 Algorithms Job Interview/codes/23.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/23.c rename to 9 Algorithms Job Interview/codes/23.c diff --git a/9 Algorithms Job Interview/测试代码/24.c b/9 Algorithms Job Interview/codes/24.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/24.c rename to 9 Algorithms Job Interview/codes/24.c diff --git a/9 Algorithms Job Interview/测试代码/25.c b/9 Algorithms Job Interview/codes/25.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/25.c rename to 9 Algorithms Job Interview/codes/25.c diff --git a/9 Algorithms Job Interview/测试代码/26.c b/9 Algorithms Job Interview/codes/26.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/26.c rename to 9 Algorithms Job Interview/codes/26.c diff --git a/9 Algorithms Job Interview/测试代码/27.c b/9 Algorithms Job Interview/codes/27.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/27.c rename to 9 Algorithms Job Interview/codes/27.c diff --git a/9 Algorithms Job Interview/测试代码/28.c b/9 Algorithms Job Interview/codes/28.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/28.c rename to 9 Algorithms Job Interview/codes/28.c diff --git a/9 Algorithms Job Interview/测试代码/4 numer/Power.c b/9 Algorithms Job Interview/codes/4 numer/Power.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/4 numer/Power.c rename to 9 Algorithms Job Interview/codes/4 numer/Power.c diff --git a/9 Algorithms Job Interview/测试代码/4 numer/integer_to_bin.c b/9 Algorithms Job Interview/codes/4 numer/integer_to_bin.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/4 numer/integer_to_bin.c rename to 9 Algorithms Job Interview/codes/4 numer/integer_to_bin.c diff --git a/9 Algorithms Job Interview/测试代码/4 numer/isSquare.c b/9 Algorithms Job Interview/codes/4 numer/isSquare.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/4 numer/isSquare.c rename to 9 Algorithms Job Interview/codes/4 numer/isSquare.c diff --git a/9 Algorithms Job Interview/测试代码/4 numer/one_appear_count_by_binary.c b/9 Algorithms Job Interview/codes/4 numer/one_appear_count_by_binary.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/4 numer/one_appear_count_by_binary.c rename to 9 Algorithms Job Interview/codes/4 numer/one_appear_count_by_binary.c diff --git a/9 Algorithms Job Interview/测试代码/4 numer/string_to_integer.c b/9 Algorithms Job Interview/codes/4 numer/string_to_integer.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/4 numer/string_to_integer.c rename to 9 Algorithms Job Interview/codes/4 numer/string_to_integer.c diff --git a/9 Algorithms Job Interview/测试代码/4-1.c b/9 Algorithms Job Interview/codes/4-1.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/4-1.c rename to 9 Algorithms Job Interview/codes/4-1.c diff --git a/9 Algorithms Job Interview/测试代码/5 array/delete_occurence_character.c b/9 Algorithms Job Interview/codes/5 array/delete_occurence_character.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/5 array/delete_occurence_character.c rename to 9 Algorithms Job Interview/codes/5 array/delete_occurence_character.c diff --git a/9 Algorithms Job Interview/测试代码/5 array/factorial.c b/9 Algorithms Job Interview/codes/5 array/factorial.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/5 array/factorial.c rename to 9 Algorithms Job Interview/codes/5 array/factorial.c diff --git a/9 Algorithms Job Interview/测试代码/5 array/fibonacci.c b/9 Algorithms Job Interview/codes/5 array/fibonacci.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/5 array/fibonacci.c rename to 9 Algorithms Job Interview/codes/5 array/fibonacci.c diff --git a/9 Algorithms Job Interview/测试代码/5 array/longest_continuious_number.c b/9 Algorithms Job Interview/codes/5 array/longest_continuious_number.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/5 array/longest_continuious_number.c rename to 9 Algorithms Job Interview/codes/5 array/longest_continuious_number.c diff --git a/9 Algorithms Job Interview/测试代码/5 array/print_continuous_sequence_sum.c b/9 Algorithms Job Interview/codes/5 array/print_continuous_sequence_sum.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/5 array/print_continuous_sequence_sum.c rename to 9 Algorithms Job Interview/codes/5 array/print_continuous_sequence_sum.c diff --git a/9 Algorithms Job Interview/测试代码/5.c b/9 Algorithms Job Interview/codes/5.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/5.c rename to 9 Algorithms Job Interview/codes/5.c diff --git a/9 Algorithms Job Interview/测试代码/6 matrix/print_matrix.c b/9 Algorithms Job Interview/codes/6 matrix/print_matrix.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/6 matrix/print_matrix.c rename to 9 Algorithms Job Interview/codes/6 matrix/print_matrix.c diff --git a/9 Algorithms Job Interview/测试代码/7 bianrytree/binary_search.c b/9 Algorithms Job Interview/codes/7 bianrytree/binary_search.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/7 bianrytree/binary_search.c rename to 9 Algorithms Job Interview/codes/7 bianrytree/binary_search.c diff --git a/9 Algorithms Job Interview/测试代码/bt1.c b/9 Algorithms Job Interview/codes/7 bianrytree/bt1.c similarity index 71% rename from 9 Algorithms Job Interview/测试代码/bt1.c rename to 9 Algorithms Job Interview/codes/7 bianrytree/bt1.c index 8816c9e..7e72477 100644 --- a/9 Algorithms Job Interview/测试代码/bt1.c +++ b/9 Algorithms Job Interview/codes/7 bianrytree/bt1.c @@ -3,11 +3,9 @@ 二叉查找树变成双向链表 */ -strcut BSTreeNode{ - +typedef struct BSTreeNode{ int m_nValue; - BSTreeNode *m_pLeft,m_pRight; - + struct BSTreeNode *m_pLeft, *m_pRight; }BSTree; void convertDoubleLinks(BSTree *root){ diff --git a/9 Algorithms Job Interview/测试代码/7.c b/9 Algorithms Job Interview/codes/7.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/7.c rename to 9 Algorithms Job Interview/codes/7.c diff --git a/9 Algorithms Job Interview/测试代码/8.c b/9 Algorithms Job Interview/codes/8.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/8.c rename to 9 Algorithms Job Interview/codes/8.c diff --git a/9 Algorithms Job Interview/测试代码/c1.c b/9 Algorithms Job Interview/codes/c1.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c1.c rename to 9 Algorithms Job Interview/codes/c1.c diff --git a/9 Algorithms Job Interview/测试代码/c10.c b/9 Algorithms Job Interview/codes/c10.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c10.c rename to 9 Algorithms Job Interview/codes/c10.c diff --git a/9 Algorithms Job Interview/测试代码/c11-2.c b/9 Algorithms Job Interview/codes/c11-2.c similarity index 90% rename from 9 Algorithms Job Interview/测试代码/c11-2.c rename to 9 Algorithms Job Interview/codes/c11-2.c index fda7caf..e5c3e4b 100644 --- a/9 Algorithms Job Interview/测试代码/c11-2.c +++ b/9 Algorithms Job Interview/codes/c11-2.c @@ -12,7 +12,7 @@ int main() { char ch = 'a'; - foobar1(33, ch); + foobar1(); foobar2(); return 0; } diff --git a/9 Algorithms Job Interview/测试代码/c11.c b/9 Algorithms Job Interview/codes/c11.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c11.c rename to 9 Algorithms Job Interview/codes/c11.c diff --git a/9 Algorithms Job Interview/测试代码/c12.c b/9 Algorithms Job Interview/codes/c12.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c12.c rename to 9 Algorithms Job Interview/codes/c12.c diff --git a/9 Algorithms Job Interview/测试代码/c13-1.c b/9 Algorithms Job Interview/codes/c13-1.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c13-1.c rename to 9 Algorithms Job Interview/codes/c13-1.c diff --git a/9 Algorithms Job Interview/测试代码/c13-2.c b/9 Algorithms Job Interview/codes/c13-2.c similarity index 85% rename from 9 Algorithms Job Interview/测试代码/c13-2.c rename to 9 Algorithms Job Interview/codes/c13-2.c index 7b8ea97..cbb3ff5 100644 --- a/9 Algorithms Job Interview/测试代码/c13-2.c +++ b/9 Algorithms Job Interview/codes/c13-2.c @@ -1,9 +1,8 @@ #include "c13-1.c" - extern int *arr; + int main() { - arr[1] = 100; return 0; } diff --git a/9 Algorithms Job Interview/测试代码/c14.c b/9 Algorithms Job Interview/codes/c14.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c14.c rename to 9 Algorithms Job Interview/codes/c14.c diff --git a/9 Algorithms Job Interview/测试代码/c15.c b/9 Algorithms Job Interview/codes/c15.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c15.c rename to 9 Algorithms Job Interview/codes/c15.c diff --git a/9 Algorithms Job Interview/测试代码/c16.c b/9 Algorithms Job Interview/codes/c16.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c16.c rename to 9 Algorithms Job Interview/codes/c16.c diff --git a/9 Algorithms Job Interview/测试代码/c17.c b/9 Algorithms Job Interview/codes/c17.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c17.c rename to 9 Algorithms Job Interview/codes/c17.c diff --git a/9 Algorithms Job Interview/测试代码/c18.c b/9 Algorithms Job Interview/codes/c18.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c18.c rename to 9 Algorithms Job Interview/codes/c18.c diff --git a/9 Algorithms Job Interview/测试代码/c19.c b/9 Algorithms Job Interview/codes/c19.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c19.c rename to 9 Algorithms Job Interview/codes/c19.c diff --git a/9 Algorithms Job Interview/测试代码/c2.c b/9 Algorithms Job Interview/codes/c2.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c2.c rename to 9 Algorithms Job Interview/codes/c2.c diff --git a/9 Algorithms Job Interview/测试代码/c20.c b/9 Algorithms Job Interview/codes/c20.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c20.c rename to 9 Algorithms Job Interview/codes/c20.c diff --git a/9 Algorithms Job Interview/测试代码/c3.c b/9 Algorithms Job Interview/codes/c3.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c3.c rename to 9 Algorithms Job Interview/codes/c3.c diff --git a/9 Algorithms Job Interview/测试代码/c4.c b/9 Algorithms Job Interview/codes/c4.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c4.c rename to 9 Algorithms Job Interview/codes/c4.c diff --git a/9 Algorithms Job Interview/测试代码/c5.c b/9 Algorithms Job Interview/codes/c5.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c5.c rename to 9 Algorithms Job Interview/codes/c5.c diff --git a/9 Algorithms Job Interview/测试代码/c6.c b/9 Algorithms Job Interview/codes/c6.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c6.c rename to 9 Algorithms Job Interview/codes/c6.c diff --git a/9 Algorithms Job Interview/测试代码/c7.c b/9 Algorithms Job Interview/codes/c7.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c7.c rename to 9 Algorithms Job Interview/codes/c7.c diff --git a/9 Algorithms Job Interview/测试代码/c8.c b/9 Algorithms Job Interview/codes/c8.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c8.c rename to 9 Algorithms Job Interview/codes/c8.c diff --git a/9 Algorithms Job Interview/测试代码/c9.c b/9 Algorithms Job Interview/codes/c9.c similarity index 100% rename from 9 Algorithms Job Interview/测试代码/c9.c rename to 9 Algorithms Job Interview/codes/c9.c diff --git a/9 Algorithms Job Interview/测试代码/most_visit_ip.c b/9 Algorithms Job Interview/codes/most_visit_ip.c similarity index 99% rename from 9 Algorithms Job Interview/测试代码/most_visit_ip.c rename to 9 Algorithms Job Interview/codes/most_visit_ip.c index 5c64dca..8ca03fd 100644 --- a/9 Algorithms Job Interview/测试代码/most_visit_ip.c +++ b/9 Algorithms Job Interview/codes/most_visit_ip.c @@ -8,17 +8,12 @@ #define test_file_path "./ip.txt" #define ip_count 100000000 //随机1亿个IP #define tmp_file_count 32 - #define mem_count 128*1024*1028 //128MB个IP空间 - int hash(unsigned i){ - return i>>27; - } - int main(){ @@ -52,9 +47,6 @@ int main(){ } } - - - //开始读测试数据IP,按IP,映射到32个文件中 FILE *testfd = fopen(test_file_path2,"r"); if (!testfd) @@ -76,8 +68,6 @@ int main(){ } - - // 依次读入每个文件并统计, hash_map 统计每个区间段的最大IP int hash_map[mem_count]; int max_ip;