Monday, December 9, 2013

Graphs And Graph Algorithms: The Holy Grail of Computer Science


#define len 6//number of nodes

struct node 
{
    struct node *next;
    int vertex;
};
//function to allocate space for one node
struct node *nalloc(void)
{
    return (struct node *)malloc(sizeof(struct node));    
}
//function for making a node from int
struct node *makenode(int vertex)
{
    struct node *temp=nalloc();
    temp->vertex=vertex;
    temp->next=NULL;
    return temp;
}
//function for connecting two nodes.
struct node *addnode(struct node *p, int vertex)
{
       if(p == NULL) //if first node in list
       {   
           p=nalloc();//make space for p
           p->next=NULL;
           p->vertex=vertex;
       }else{//this is not first node
           p->next=nalloc();//make space
           p->next->vertex=vertex;
       }
       return p;
}
int main()
{    
    struct node{
          struct node* next;
          int vertex;
};
    struct node array[len]={{NULL,1},
                            {NULL,2},
                            {NULL,3},
                            {NULL,4},
                            {NULL,5},
                            {NULL,6},
    };//end arraylist
  
    //print each head of list
    int j;
    for(j=0; jnext->vertex);
     
return 0;
}
I call graphs and graph algorithms the holy grail of CS because they have suchwide, disparate applications throughout the sciences. This post represents myfirst clumsy grope at the problems posed by considering the processing of graphs.

No comments:

Post a Comment