手撕快排 还是把快排纹在手上吧

2021-10-13 14:27:54 浏览数 (1)

代码语言:javascript复制
int PartSort(int* array,int left,int right)
{
	int& key = array[right];
	while(left < right)
	{
		while(left < right && array[left] <= key)
		{
			  left;
		}
		while(left < right && array[right] >= key)
		{
			--right;
		}
		swap(array[left],array[right]);
	}
	swap(array[left],key);
	return left;
}

反转链表也纹在手上吧

代码语言:javascript复制
ListNode* ReverseList(ListNode* pHead)
{
    ListNode* pReversedHead = NULL;
    ListNode* pNode = pHead;
    ListNode* pPrev = NULL;
    while(pNode != NULL)
    {
        ListNode* pNext = pNode->m_pNext;

        if(pNext == NULL)
            pReversedHead = pNode;

        pNode->m_pNext = pPrev;

        pPrev = pNode;
        pNode = pNext;
    }

    return pReversedHead;
}

0 人点赞