This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
git filter-branch --force --env-filter ' | |
OLD_EMAIL="your-old-email@example.com" | |
CORRECT_NAME="Your Correct Name" | |
CORRECT_EMAIL="your-correct-email@example.com" | |
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ] | |
then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// QuickSort | |
int Partition(int data[], int length, int start, int end) { | |
if(data == nullptr || length <= 0 || start < 0 || end >= length) { | |
throw new std::exception("Invalid parameters"); | |
} | |
// 生成随机数 | |
int index = RandomInRange(start, end); | |
// 交换两个数字,不交换指针 | |
Swap(&data[index], &data[end]); | |
int small = start - 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
long long Fibonacci(unsigned int n) { | |
if(n <= 0) { | |
return 0; | |
} | |
if(n == 1) { | |
return 1; | |
} | |
return Fibonacci(n-1) + Fibonacci(n-2); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> void CQueue<T>::appendTail(const T& element) { | |
stack1.push(element); | |
} | |
template<typename T> T CQueue<T>::deleteHead() { | |
if(stack2.size() <= 0) { | |
while(stack1.size() > 0) { | |
T& data = stack1.top(); | |
stack1.pop(); | |
stack2.push(data); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BinaryTreeNode *GetNext(BinaryTreeNode *pNode) { | |
if(pNode == nullptr) { | |
return nullptr; | |
} | |
// 初始化下一个节点 | |
BinaryTreeNode *pNext = nullptr; | |
if(pNode->m_pRight != nullptr) { | |
BinaryTreeNode *pRight = pNode->m_pRight; | |
while(pRight->m_pLeft != nullptr) { | |
pRight = pRight->m_pLeft; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BinaryTreeNode *Construct(int *preorder, int *inorder, int length) { | |
if(preorder == nullptr || inorder == nullptr || length <= 0) { | |
return nullptr; | |
} | |
return ConstructCore(preorder, preorder + length - 1, inorder, inorder + length - 1); | |
} | |
BinaryTreeNode *ConstructCore(int *startPreorder, int *endPreorder, int *startInorder, int *endInorder) { | |
int rootValue == startPreorder[0]; | |
// 初始化二叉树 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void PrintListReversingly_Iteratively(ListNode *pHead) { | |
std::stack<ListNode*> nodes; | |
// 注意理解指向指针的指针 | |
ListNode *pNode = pHead; | |
while(pNode != nullptr) { | |
nodes.push(pNode) | |
pNode = pNode->m_pNext; | |
} | |
while(!nodes.empty()) { | |
pNode = nodes.top(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ReplaceBlank(char string[], int length) { | |
if(string == nullptr || length <= 0) { | |
return; | |
} | |
int originalLength = 0; | |
int numberOfBlank = 0; | |
int i = 0; | |
while(string[i] != '\0') { | |
++originalLength; | |
if(sting[i] == ' ') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int getDuplication(const int *numbers, int length) { | |
if(numbers == nullptr || length <= 0) { | |
return -1; | |
} | |
int start = 1; | |
int end = length-1; | |
while(end >= start) { | |
int middle = ((end - start) >> 1) + start; | |
int count = countRange(numbers, length, start, middle); | |
if(count > (middle - start + 1)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool duplicate(int numbers[], int length, int *duplication) { | |
if(numbers == nullptr || length <= 0) { | |
return false; | |
} | |
for(int i = 0; i < length; ++i) { | |
if(numbers[i] < 0 || numbers[i] > length-1) { | |
return false; | |
} | |
} | |
for(int i = 0; i < length; ++i) { |
NewerOlder