Guest User

Untitled

a guest
Apr 9th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. //graph head
  6. typedef struct graphH {
  7.     int count;
  8.     struct graphV *firstV;
  9. } HEAD;
  10.  
  11. //graph vertex
  12. typedef struct graphV {
  13.     struct graphV *nextV;
  14.     char name;
  15.     int degree;
  16.     int processed;
  17.     struct graphA *firstArc;
  18. } VERTEX;
  19.  
  20. //graph arc
  21. typedef struct graphA {
  22.     struct graphV *destination;
  23.     struct graphA *nextArc;
  24. } ARC;
  25.  
  26. //prototype declarations
  27. HEAD *createGraph (void);
  28. HEAD *buildGraph (void);
  29. void insertVertex (HEAD *pass_head, char x);
  30.  
  31. int main (void)
  32. {
  33.     HEAD *graph_head;
  34.    
  35.     graph_head=buildGraph();
  36.  
  37.     printf("%c", graph_head->firstV->name);
  38.     printf("END\n");
  39.     return 0;
  40. }
  41.  
  42. // ------------------------------> createGraph
  43. HEAD *createGraph (void)
  44. {
  45.     int i;
  46.     HEAD *temp_head;
  47.     temp_head = (HEAD *) malloc (sizeof (HEAD));
  48.    
  49.     if (temp_head)
  50.     {
  51.         temp_head->count=0;
  52.         temp_head->firstV=NULL;
  53.     }
  54.     return temp_head;
  55. }
  56.  
  57. // ------------------------------> buildGraph
  58. HEAD *buildGraph (void)
  59. {
  60.     HEAD *temp_head;
  61.  
  62.     temp_head=createGraph();
  63.  
  64.     insertVertex(temp_head, 'c');
  65.     /*insertVertex(temp_head, 'd');
  66.     insertVertex(temp_head, 'e');
  67.     insertVertex(temp_head, 'f');
  68.     insertVertex(temp_head, 'g');
  69.     insertVertex(temp_head, 'h');
  70.     */
  71.     return temp_head;
  72. }
  73.  
  74. // ------------------------------> insertVertex
  75. void insertVertex (HEAD *pass_head, char x)
  76. {
  77.     int i=0;
  78.     VERTEX *hold_vertex;
  79.     VERTEX *ptr_vertex;
  80.  
  81.     hold_vertex = (VERTEX *) malloc (sizeof (VERTEX));
  82.    
  83.     hold_vertex->nextV=NULL;
  84.     hold_vertex->name=x;
  85.     hold_vertex->degree=0;
  86.     hold_vertex->processed=0;
  87.     hold_vertex->firstArc=NULL;
  88.    
  89.     pass_head->count++;
  90.     ptr_vertex=(VERTEX *)(pass_head->firstV);
  91.    
  92.     if (pass_head->count==1)
  93.         ptr_vertex=hold_vertex;
  94.     else
  95.     {
  96.        
  97.     }
  98.     return;
  99. }
  100.  
  101. void insertArc (HEAD *pass_head, char *from_pass_name, char *to_pass_name)
  102. {
  103.     int i=0;
  104.     ARC *hold_arc;
  105.     VERTEX *ptr_vertex;
  106.    
  107.     hold_arc = (ARC *) malloc (sizeof(ARC));
  108.     ptr_vertex=pass_head->firstV;
  109.    
  110.     for (i=0; i<pass_head->count; i++)
  111.     {
  112.         /*if (strcmp(from_pass_name, ptr_vertex->name) == 0)
  113.         {
  114.            
  115.         }*/
  116.        
  117.         ptr_vertex=ptr_vertex->nextV;
  118.     }
  119.    
  120.     return;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment