hello-algo/codes/cpp
KLYkl 9e914f8792
Update array_deque.cpp
将43行的return (i + capacity()) % capacity();改为return (i % capacity() + capacity()) % capacity();
原因:原来的表达式“(i + capacity()) % capacity();”如果i是负数的话,需要保证capacity() >= -i。而更改后的表达式“ (i % capacity() + capacity()) % capacity();” 中的先对i取模相加,最后再取模操作会确保结果是一个非负整数,并且不会超过 capacity() 的值。这是因为取模操作会返回一个在 0 到 capacity() - 1 范围内的数,即使原始的和可能是负数。保证函数index()的传入形参i<-capacity()不会崩溃,且能正确返回 0 到 capacity() - 1 范围内的的索引值。
2024-05-17 13:33:46 +08:00
..
chapter_array_and_linkedlist Some improvements (#1073) 2024-02-07 22:21:18 +08:00
chapter_backtracking Some improvements (#1073) 2024-02-07 22:21:18 +08:00
chapter_computational_complexity fix: Use int instead of float for the example code of log time complexity (#1164) 2024-03-23 02:17:48 +08:00
chapter_divide_and_conquer Some improvements (#1073) 2024-02-07 22:21:18 +08:00
chapter_dynamic_programming Some improvements (#1073) 2024-02-07 22:21:18 +08:00
chapter_graph feat: Add glossary and description for "哈希集合" (#1310) 2024-04-28 22:00:25 +08:00
chapter_greedy Some improvements (#1073) 2024-02-07 22:21:18 +08:00
chapter_hashing Bug fixes and improvements (#1348) 2024-05-06 14:44:48 +08:00
chapter_heap Some improvements (#1073) 2024-02-07 22:21:18 +08:00
chapter_searching Some improvements (#1073) 2024-02-07 22:21:18 +08:00
chapter_sorting Fix the driver code of quick_sort.cpp (#1219) 2024-04-04 19:37:18 +08:00
chapter_stack_and_queue Update array_deque.cpp 2024-05-17 13:33:46 +08:00
chapter_tree Bug fixes and improvements (#1252) 2024-04-09 19:55:59 +08:00
utils Fix bugs and harmonize the code comments (#1199) 2024-03-31 03:06:41 +08:00
.gitignore Update CMakeLists.txt for C++ 2023-03-15 01:43:28 +08:00
CMakeLists.txt Add the chapter of greedy. (#633) 2023-07-20 18:26:54 +08:00