算法
cbmj11
这个作者很懒,什么都没留下…
展开
-
快速排序算法
算法思想: 给定一个基准值1, 比基准值1小的都放右边, 比基准值大的都放左边 在基准值1的左边和右边分别再选择一个基准值进行排序 知道全部小区域都排序 典型的分治法 Paritition1(int A[], int low, int high) { int pivot = A[low]; while (low < high) { while (low < high && A[high] >= pivot) { –high; } A[low] = A[high]; wh原创 2022-04-05 20:38:40 · 402 阅读 · 0 评论 -
链表-链表反转
头插入法: 开辟一个新链表Presult头为空,通过指针pfor遍历给定的链表, 每个node都插入到Presult头部, 注意: 1.1. 每次插入node时, Presult->next都会更改, 需要先保存,保证给定链表不断 1.2. 在 Presult 头部插入后,Pfor要改为之前保存的tmp; class Solution { public: ListNode* reverseList(ListNode* head) { if((head == NULL) ||.原创 2022-03-05 16:26:48 · 185 阅读 · 0 评论