Minimum path for single-node authorization C Language

Source: Internet
Author: User

In other words, I wrote this thing for more than four days. I wrote it for 10 hours today and finally finished it. I feel a lot of feelings .!

The new data structure needs to be used in combination with the previous data structure. I designed it along the train of thought, and then started to write it.

From the hash table, to the adjacent table, and then to the binary heap, I was very worried. As a result, I was not so skilled and could not be completed quickly. I am very happy to be able to complete it. haha.

Many concepts are written with the flexibility of writing code. I think the book has been mentioned before.

The understanding of the hash table and the binary heap is always getting deeper, mainly because the two chapters are quite anxious. so now it's time to feel uncomfortable. even though it is complicated ,.

I feel unfamiliar with multi-file compilation. I will sum up my experience in the future coding process and read relevant books.

The adjacent table implementation file is new because it is an authorized graph and is forced to be modified. It is more universal and convenient to use.

I don't want to talk about it. It hurts my neck. I went to bed and prepared. I started to post code. Haha.

/* 9-9 (B)-12-12-12.12.c -- Chapter 9, Question 9 */<br/> # include <stdio. h> <br/> # include <stdlib. h> <br/> # include "binary_heap.h" </P> <p> int main (void); <br/> int Dijkstra (const adjacenty_list * padj, const hash_table * const PHT, const int start); </P> <p> int main (void) <br/>{< br/> adjacenty_list adj; <br/> hash_table HT; <br/> int capacity = 11; </P> <p> initialize_h (& HT, capacity * 2 ); <br/> initialize_a (& adj, capacity); <br/> initializealine_a (& adj, & HT, 0,'s ', 0, 6, 'A', 1, 'D', 4, 'G', 6); <br/> initializealine_a (& adj, & HT, 1, 'A', 2, 4, 'B ', 2, 'E', 2); <br/> initializealine_a (& adj, & HT, 2, 'B', 1, 2, 'C', 2 ); <br/> initializealine_a (& adj, & HT, 3, 'C', 3, 2, 't', 4); <br/> initializealine_a (& adj, & HT, 4, 'D', 2, 4, 'A', 3, 'E', 3); <br/> initializealine_a (& adj, & HT, 5, 'E', 4, 6, 'C', 2, 'F', 3, 'I', 3); <br/> initializealine_a (& adj, & HT, 6, 'F', 2, 4, 'C', 1, 't', 3); <br/> initializealine_a (& adj, & HT, 7, 'G', 1, 6, 'D', 2, 'E', 1, 'h', 6); <br/> initializealine_a (& adj, & HT, 8, 'h', 1, 4, 'E', 2, 'I', 3); <br/> initializealine_a (& adj, & HT, 9, 'I', 2, 4, 'F', 1, 't', 4); <br/> initializealine_a (& adj, & HT, 10,'t ', 3, 0); <br/> Dijkstra (& adj, & HT, 0); <br/> printadjacenty_list_a (& adj, & HT ); </P> <p> release_h (& HT); <br/> release_a (& adj); </P> <p> return 0; <br/>}</P> <p> int Dijkstra (const adjacenty_list * padj, const hash_table * const PHT, const int start) <br/>{< br/> binary_heap BH; <br/> vertex * V; <br/> adjoin_to_vertex * w; <br/> int capacity = (* padj) -> capacity, I; </P> <p> initialize_ B (& BH, capacity * 2); <br/> (* padj)-> list [start]. dist = 0; <br/> for (I = 0; I <capacity; I ++) <br/> insert_ B (& BH, (* padj) -> List + I); <br/> while (1) <br/>{< br/> DO <br/> {<br/> V = deletemin_ B (& BH ); <br/> If (negativeinfinity = V-> Dist) <br/> break; <br/>}< br/> while (true = (* Pht) -> lists [V-> hash_value]. be_deleted) <br/>; <br/> If (negativeinfinity = V-> Dist) <br/> break; <br/> (* Pht) -> lists [V-> hash_value]. be_deleted = true; <br/> V-> known = true; <br/> W = V-> adjoin_to; <br/> while (W) <br/>{< br/> If (false = (* padj)-> list [(* Pht)-> lists [w-> hash_value]. index_in_adjacenty_list]. known) <br/>{< br/> If (V-> Dist + w-> cvw <(* padj)-> list [(* Pht) -> lists [w-> hash_value]. index_in_adjacenty_list]. dist) <br/>{< br/> (* padj)-> list [(* Pht)-> lists [w-> hash_value]. index_in_adjacenty_list]. dist = V-> Dist + w-> cvw; <br/> insert_ B (& BH, (* padj)-> List + (* Pht) -> lists [w-> hash_value]. index_in_adjacenty_list); <br/> (* padj)-> list [(* Pht)-> lists [w-> hash_value]. index_in_adjacenty_list]. path = (* Pht)-> lists [V-> hash_value]. name; <br/>}< br/> W = W-> next; <br/>}< br/> release_ B (& BH); </P> <p> return 1; <br/>}

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.