Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- //graph head
- typedef struct graphH {
- int count;
- struct graphV *firstV;
- } HEAD;
- //graph vertex
- typedef struct graphV {
- struct graphV *nextV;
- char name;
- int degree;
- int processed;
- struct graphA *firstArc;
- } VERTEX;
- //graph arc
- typedef struct graphA {
- struct graphV *destination;
- struct graphA *nextArc;
- } ARC;
- //prototype declarations
- HEAD *createGraph (void);
- HEAD *buildGraph (void);
- void insertVertex (HEAD *pass_head, char x);
- int main (void)
- {
- HEAD *graph_head;
- graph_head=buildGraph();
- printf("%c", graph_head->firstV->name);
- printf("END\n");
- return 0;
- }
- // ------------------------------> createGraph
- HEAD *createGraph (void)
- {
- int i;
- HEAD *temp_head;
- temp_head = (HEAD *) malloc (sizeof (HEAD));
- if (temp_head)
- {
- temp_head->count=0;
- temp_head->firstV=NULL;
- }
- return temp_head;
- }
- // ------------------------------> buildGraph
- HEAD *buildGraph (void)
- {
- HEAD *temp_head;
- temp_head=createGraph();
- insertVertex(temp_head, 'c');
- /*insertVertex(temp_head, 'd');
- insertVertex(temp_head, 'e');
- insertVertex(temp_head, 'f');
- insertVertex(temp_head, 'g');
- insertVertex(temp_head, 'h');
- */
- return temp_head;
- }
- // ------------------------------> insertVertex
- void insertVertex (HEAD *pass_head, char x)
- {
- int i=0;
- VERTEX *hold_vertex;
- VERTEX *ptr_vertex;
- hold_vertex = (VERTEX *) malloc (sizeof (VERTEX));
- hold_vertex->nextV=NULL;
- hold_vertex->name=x;
- hold_vertex->degree=0;
- hold_vertex->processed=0;
- hold_vertex->firstArc=NULL;
- pass_head->count++;
- ptr_vertex=(VERTEX *)(pass_head->firstV);
- if (pass_head->count==1)
- ptr_vertex=hold_vertex;
- else
- {
- }
- return;
- }
- void insertArc (HEAD *pass_head, char *from_pass_name, char *to_pass_name)
- {
- int i=0;
- ARC *hold_arc;
- VERTEX *ptr_vertex;
- hold_arc = (ARC *) malloc (sizeof(ARC));
- ptr_vertex=pass_head->firstV;
- for (i=0; i<pass_head->count; i++)
- {
- /*if (strcmp(from_pass_name, ptr_vertex->name) == 0)
- {
- }*/
- ptr_vertex=ptr_vertex->nextV;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment