📄 mergesort.h
字号:
Node* merge(Node*first,Node*second)
{
Node* head = new Node;
Node*current;
current=head;
while(first != NULL && second !=NULL)
{
if(first->data < second-> data)
{
current-> next = first;
first = first-> next;
current = current-> next;
}
else
{
current-> next = second;
second = second-> next;
current = current-> next;
}
}
while(first != NULL)
{
current-> next = first;
first = first-> next;
current = current-> next;
}
while(second != NULL)
{
current-> next = second;
second = second-> next;
current = current-> next;
}
return head-> next;
}
Node* MergeSort(Node*toSortList)
{
Node* first;
Node* second;
first = toSortList;
second = toSortList->next;
if(first == NULL || second == NULL) return toSortList;
while(second != NULL && second->next != NULL)
{
toSortList = toSortList-> next;
second = second->next->next; //填空
}
second = toSortList->next; //填空
toSortList->next = NULL; //填空
return merge(MergeSort(first), MergeSort(second));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -