ALL > Computer and Education > courses > university courses > undergraduate courses > An Overview of Computer Science > zstu-(2019-2020-1) class > >
homework 4-2 Version 0
👤 Author: by uniiiquexiaoutlookcom 2019-11-14 13:52:50
#include
using namespace std;
int n,len=0,heap[10086];
void fup(int u)
{
while(1)
{
if(u==1)break;
int fa=u/2;
if(heap[fa] < heap[u])
{
swap(heap[fa],heap[u]);
u=fa;
}
else break;
}
}
void fdown(int u)
{
while(1)
{
int lc=u*2;
int rc=lc+1;
int ll;
if(lc>len)break;
if(lc==len)ll=lc;
else
{
if(heap[lc]>heap[rc])ll=lc;
else ll=rc;
}
if(heap[u] {
swap(heap[u],heap[ll]);
u=ll;
}
else break;
}
}
int main()

Please login to reply. Login

Reversion History

Loading...
No reversions found.