Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)

简介: Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)

题目链接:点击打开链接

题目大意:略。

解题思路:略。

AC 代码

voidmerge_pass( ElementTypelist[], ElementTypesorted[], intN, intlength )
{
intidx=0, p1=0, len1=p1+length, p2=len1, len2=p2+length;
intfirst=0;
while(1)
    {
if(len2>N)
        {
len2=N;
first=1; // 最后一组        }
while(p1<len1&&p2<len2)
        {
if(list[p1]<list[p2]) sorted[idx++]=list[p1++];
elsesorted[idx++]=list[p2++];
        }
while(p1<len1) sorted[idx++]=list[p1++];
while(p2<len2) sorted[idx++]=list[p2++];
p1=len2, len1=p1+length;
p2=len1, len2=p2+length;
if(first) return;
    }
}
目录
相关文章
|
机器学习/深度学习 算法
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
211 0
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
|
存储 容器
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
221 0
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
105 0
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
112 0
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
114 0
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
126 0
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
102 0
Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)
Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)
110 0
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
142 0
Data Structures and Algorithms (English) - 6-1 Deque(25 分)
Data Structures and Algorithms (English) - 6-1 Deque(25 分)
100 0