Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)

简介: Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)

题目链接:点击打开链接

题目大意:略。

解题思路:略。

AC 代码

voidswap(ElementType*a, ElementType*b)
{
ElementTypec=*a;
*a=*b;
*b=c;
return;
}
voidPercolateUp( intp, PriorityQueueH )
{
while((p>>1)>=1)
    {
if(H->Elements[p]<H->Elements[p>>1]) swap(&(H->Elements[p]),&(H->Elements[p>>1]));
elsereturn;
p>>=1;
    }
}
voidPercolateDown( intp, PriorityQueueH )
{
intlen=H->Size, t;
while((p<<1)<=len)
    {
t=p<<1;
if(t<len&&H->Elements[t]>H->Elements[t+1]) t++;
if(H->Elements[t]<H->Elements[p]) swap(&(H->Elements[t]),&(H->Elements[p]));
elsereturn;
p=t;
    }
}
目录
相关文章
|
机器学习/深度学习 算法
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 分)
209 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 分)
219 0
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
185 0
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
108 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 分)
109 0
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
Data Structures and Algorithms (English) - 6-7 Isomorphic(20 分)
124 0
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
100 0
Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)
Data Structures and Algorithms (English) - 7-8 File Transfer(25 分)
108 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 分)
140 0
Data Structures and Algorithms (English) - 6-1 Deque(25 分)
Data Structures and Algorithms (English) - 6-1 Deque(25 分)
98 0