Data Structure-Key Path AOE for C language implementation

Source: Internet
Author: User

Data Structure-Key Path AOE for C language implementation

// Key Path AOE // Yang Xin # include
 
  
# Include
  
   
# Include
   
    
// Define the adjacent table typedef struct node {int adjvex; int w; struct node * nextedge;} edgenode; // define the edge set typedef struct {char data; int id; edgenode * firstedge;} vexnode; void CreateGraph (vexnode * Graph, int vexnumber, int arcnumber) {int I = 0, j = 0, k = 0; int begin, end, duttem; char ch; edgenode * p; for (I = 0; I
    
     
); For (k = 0; kadjvex = end-1; p-> w = duttem; Graph [end-1]. id ++; p-> nextedge = Graph [begin-1]. firstedge; Graph [begin-1]. firstedge = p ;}} int SearchMapPath (vexnode * Graph, int vexnumber, int arcnumber) {int totaltime = 0; int m = 0; int I, j, k, t; char sv [100]; int front, rear; int * topology_queue, * vl, * ve, * el, * ee; front = rear =-1; t = 0; topology_queue = (int *) malloc (vexnumber * sizeof (int); vl = (int *) malloc (vexnumber * sizeof (int); ve = (int *) malloc (vexnumber * sizeof (int); el = (int *) malloc (arcnumber * sizeof (int); ee = (int *) malloc (arcnumber * sizeof (int); edgenode * p; for (I = 0; I
     
      
Adjvex; Graph [k]. id --; if (ve [j] + p-> w> ve [k]) ve [k] = ve [j] + p-> w; if (Graph [k]. id = 0) topology_queue [++ rear] = k; p = p-> nextedge ;}} if (m
      
        = 0; I --) {j = topology_queue [I]; p = Graph [j]. firstedge; while (p) {k = p-> adjvex; if (vl [k]-p-> w)
       
         W; p = p-> nextedge;} printf (| start point | End Point | earliest start time | latest start time | difference value | whether it is a key path); I = 0; for (j = 0; j
        
          Adjvex; ee [++ I] = ve [j]; el [I] = vl [k]-p-> w; printf (| % 4c | % 4c | % 12d | % 12d | % 4d |, Graph [j]. data, Graph [k]. data, ee [I], el [I], el [I]-ee [I]); if (el [I] = ee [I]) {printf (this arc is a key activity); sv [t] = Graph [j]. data; t ++;} printf (); p = p-> nextedge;} printf (Key Path node: :); sv [t] = Graph [vexnumber-1]. data; for (I = 0; I <= t; I ++) {printf (% c, sv [I]); if (sv [I]! = Graph [vexnumber-1]. data) printf (--->);} printf (); printf (Key Path Length: % d unit time, totaltime); return 1;} int main () {int vexnumber, arcnumber, totaltime = 0; printf (enter the number of nodes in this figure :); scanf (% d, & vexnumber ); printf (enter the number of arcs in this figure :); scanf (% d, & arcnumber); vexnode * Graph = (vexnode *) malloc (vexnumber * sizeof (vexnode )); createGraph (Graph, vexnumber, arcnumber); SearchMapPath (Graph, vexnumber, arcnumber); return 0 ;}
        
       
      
     
    
   
  
 

 

Result:

 

Related Article

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.