Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct linkedlist { // linked list of ints (for use in Node)
- int index;
- struct linkedlist *next;
- } List;
- typedef struct { // a Node of a Graph
- char *name;
- List *outlist; // adjacency list
- int outdegree; // length of outlist
- //double pagerank_score; //not needed for this exercise
- } Node;
- typedef struct {
- int MaxSize;
- Node *table;
- } Graph;
- int initialize_graph (Graph *mygraph, int MaxSize)
- {
- mygraph->table = malloc(sizeof(Node) * MaxSize);
- mygraph->MaxSize = MaxSize;
- return 0;
- }
- int insert_graph_node (Graph *mygraph, int n, char *name)
- {
- strcpy(mygraph->table[n].name ,name);
- mygraph->table[n].outdegree = 0;
- mygraph->table[n].outlist = NULL;
- return 0;
- }
- int insert_graph_link (Graph *mygraph, int source, int target)
- {
- List* myList = malloc(sizeof(List));
- myList->index = target;
- myList->next = NULL;
- List* anotherList = mygraph->table[source].outlist;
- if(mygraph->table[source].outdegree == 0)
- mygraph->table[source].outlist=myList;
- else
- {
- while(anotherList->next != NULL)
- {
- anotherList = anotherList->next;
- }
- anotherList->next = myList;
- }
- mygraph->table[source].outdegree++;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement