C language for Binary heap file with Dijkstra Algorithm

Source: Internet
Author: User

/* Binary_heap.h -- binary heap file */<br/> # include "new_adjacenty_list.h" </P> <p>/* data type definition */</P> <p> typedef vertex * heap_item; <br/> typedef struct binary_heap <br/>{< br/> heap_item * heap; <br/> int capacity; <br/> int current; <br/>}* binary_heap; </P> <p>/* interface function declaration */</P> <p>/* operation: before creating and initializing a binary heap */<br/>/*: PBH points to a binary heap. capacity indicates the size of the heap */<br/>: if capacity> 0 & memory allocation is successful, 1 is returned if the heap is created; otherwise 0 */<br/>/* time complexity: O (1) */<br/> int initialize_ B (binary_heap * const PBH, const int capacity); </P> <p>/* operation: add a data field to the heap as the specified data element */<br/>/* before the operation: PBH points to an initialized binary heap, hi is the specified data to be added */<br/>/*: If the heap is not full, add a new element to the binary heap and return 1; otherwise, 0 */<br/>/* time complexity is returned: O (log n) */<br/> int insert_ B (const binary_heap * const PBH, const heap_item hi ); </P> <p>/* operation: delete and return the smallest element in the heap */<br/>/* before the operation: PBH points to an initialized binary heap */<br/>/*: If the heap is not empty, delete the minimum element in the heap and return it; otherwise, the system returns the dummy element */<br/>/* time complexity: O (log n) */<br/> heap_item deletemin_ B (const binary_heap * const PBH ); </P> <p>/* operation: before the operation, increase the value of the DIST field of the specified Element in the heap */<br/>: PHB points to an initialized binary heap. index indicates the index of the specified element, and triangle indicates the size of Delta */<br/>/* after the operation: if the heap is not empty & index is a valid index & △> = 0, the DIST field of the element whose index is indexed in the heap is increased by △, and 1 is returned; otherwise, 0 */<br/>/* time complexity is returned: O (log n) */<br/> int increasekey_ B (const binary_heap * const PBH, const int index, const int triangle); </P> <p>/* operation: before performing any operation to reduce the DIST field value of the specified Element in the heap */<br/>: PBH points to an initialized binary heap, index indicates the index of the specified element, and triangle indicates the size of Delta */<br/>/* after the operation: if the heap is not empty & index is a valid index & △> = 0, the DIST field of the element whose index is indexed in the heap is reduced by △, and 1 is returned; otherwise, 0 */<br/>/* time complexity is returned: O (log n) */<br/> int decreasekey_ B (const binary_heap * const PBH, const int index, const int triangle); </P> <p>/* operation: Release the memory space occupied by a binary heap */<br/>/* operation: PBH points to an initialized binary heap */<br/>/*: the memory occupied by the heap is released */<br/>/* time complexity: O (1) */<br/> void release_ B (const binary_heap * const PBH );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.