二項堆(減小關鍵字的值和刪除指定關鍵字)

2021-06-02 13:33:40 字數 3479 閱讀 6773

注意觀察注釋掉的**

#include  

#include  

#define  nil  9999

typedef  struct  _binheap

binheap;

binheap  *  newconstruct ( int key)

binheap  *  nilconstruct ()

else

return  nilobj;

}binheap * binheap_merge ( binheap *left , binheap *right )

if( !right)

if( left->degree < right->degree)

else

}void  re_link (binheap *left , binheap *right )

binheap * binheap_union ( binheap *left , binheap *right )

if(! x->sib)

else

else

else

}else

else

}else

}}}  

}return  wrap_head->sib;

}void insert (binheap  *newobj ,binheap * * head)

else

}void  print(binheap *head,int level)

else

}binheap  *reverse ( binheap  *head)

while( head->sib )

head->sib=left;

return  head;

}void  binheap_fix_parent (  binheap * parent_child  ,binheap *parent)

}binheap  * pop (binheap  **_head )

head=head->sib;

}wrap_head->sib=*_head;

head=wrap_head;

while(head)

head=head->sib;

}*_head=wrap_head->sib;

result=min;

binheap_fix_parent(min->child ,null);  //add  by chenbing

head= reverse  ( min->child);

*_head=binheap_union (head ,*_head);

result->sib=null;

result->child=null;

return  result;

}void  binheap_re_sib ( binheap *obj , binheap * parent_child ,binheap  *replace  )

parent_child=parent_child->sib;}}

void  binheap_adjust ( binheap * obj ,binheap  **head )

else

if( parent->parent)

else

}else

else

}parent->parent=obj;

parent->child=obj_child;

parent->sib=obj_sib;

binheap_fix_parent ( obj->child , obj);

binheap_fix_parent ( obj_child , parent);

degree=obj->degree;

obj->degree=parent->degree;

parent->degree=degree;

}else

parent=obj->parent;}}

void  binheap_dec ( binheap *obj ,int  value ,binheap  **head)

void  binheap_delete ( binheap *obj ,binheap **head )

int main()

;result=(binheap **) calloc (  sizeof (key)/sizeof (int ),sizeof (binheap *));

for(i=0;inewobj=newconstruct (key[i]); 

result[i]=newobj;

insert ( newobj , &head);  

}print(head,0);

//pop the result 

//binheap_dec (result[9] ,30 ,&head);

//binheap_dec (result[8] ,50 ,&head);

//binheap_dec (result[7] ,70 ,&head);

//binheap_dec (result[6] ,220 ,&head);

//binheap_dec (result[5] ,340 ,&head);

//binheap_dec (result[4] ,20 ,&head);

//binheap_dec (result[3] ,40 ,&head);

binheap_dec (result[2] ,60 ,&head);

//binheap_dec (result[1] ,30 ,&head);

//binheap_dec (result[0] ,10 ,&head);

printf("adjust \n");

print(head,0);

//test  delete

binheap_delete ( result[6] ,&head);

printf("delete \n");

print(head,0);

binheap_delete ( result[5] ,&head);

printf("delete \n");

print(head,0);

binheap_delete ( result[1] ,&head);

printf("delete \n");

print(head,0);

binheap_delete ( result[8] ,&head);

printf("delete \n");

print(head,0);

binheap_delete ( result[7] ,&head);

printf("delete \n");

print(head,0);

binheap_delete ( result[3] ,&head);

printf("delete \n");

print(head,0);

while(head)

}

Linux系統批量刪除包含指定關鍵字的程序

ps ef grep 指定關鍵字 grep v grep cut c 9 15 xargs kill 9 ps ef grep 指定關鍵字 grep v grep awk xargs kill 9 ps ef 檢視所有程序 grep 指定關鍵字 列出所有含有關鍵字指定關鍵字的程序 grep v gr...

堆和棧的區別。static關鍵字用法

堆和棧的區別 1 管理方式不同 2 空間大小不同 3 能否產生碎片不同 4 生長方向不同 5 分配方式不同 6 分配效率不同 管理方式 棧 系統開闢,系統釋放 堆 手動開闢,手動釋放 空間大小 一般來講在32位系統下,堆記憶體可以達到2g的空間,棧空間大小是1m。碎片問題 對於堆來講,頻繁的new ...

c 中在堆區通過new關鍵字建立二維陣列的方法

在網上搜尋如何在堆區建立二維陣列,得到以下結果 如何理解這個語句的含義呢?首先,我們都知道,在堆區中建立一維陣列的方式為 int p newint 10 那麼我們再來看這個堆區二維陣列的語句 int p 10 newint 5 10 按照鄙人的拙劣理解 語句的右半部分 new int 5 10 是在...