00001
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include "graphdefs.h"
00005
00006
00007
00008 EdgeListType * InitEdgeList(int E)
00009 {
00010 EdgeListType * edgesRec;
00011
00012 edgesRec = (EdgeListType *) malloc(sizeof(EdgeListType));
00013 _MEMCHECK(edgesRec);
00014 edgesRec->next = 0;
00015 edgesRec->edges = (Edge *) malloc(E*sizeof(Edge));
00016 _MEMCHECK(edgesRec->edges);
00017 return(edgesRec);
00018 }
00019
00020 void addEdge(VerticesListType *graph, EdgeListType * EdgeList, int v, int w)
00021 {
00022 int n, index;
00023 n = EdgeList->next;
00024 EdgeList->next++;
00025
00026
00027 ((EdgeList->edges)[n]).node1 = v;
00028 (EdgeList->edges[n]).node2 = w;
00029 index = graph->vertexArray[v].next++;
00030 graph->adjArray[ index ] = w;
00031 index = graph->vertexArray[w].next++;
00032 graph->adjArray[ index ] = v;
00033
00034 graph->vertexArray[v].degree++;
00035 graph->vertexArray[w].degree++;
00036 }
00037
00038 void printEdges(EdgeListType *EdgeList)
00039 {
00040 int i;
00041 Edge * edges;
00042 edges = EdgeList->edges;
00043 for (i=0; i< (EdgeList->next ); i++)
00044 {printf("%d\t%d\n", edges[i].node1, edges[i].node2);
00045 }
00046 }
00047
00048 int edgeExists(VerticesListType *graph, int x, int y)
00049 {
00050 int i, ind;
00051 ind = graph->vertexArray[x].adjListInd;
00052
00053 for(i=0; i< graph->vertexArray[x].degree; i++)
00054 { if (graph->adjArray[ind + i] == y) return 1;}
00055
00056 return 0;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 void addspEdge(VerticesListType *graph, EdgeListType * EdgeList, int v, int w)
00066 {
00067 int n, index,i,x,y,ind;
00068 n = EdgeList->next;
00069 EdgeList->next++;
00070
00071
00072
00073
00074 for (i=0;i<n-1;i++)
00075 if (((EdgeList->edges[i]).node1!=v) && ((EdgeList->edges[i]).node2!=w))
00076 {
00077 x=(EdgeList->edges[i]).node1;
00078 y=(EdgeList->edges[i]).node2;
00079 (EdgeList->edges[i]).node2=w;
00080 (EdgeList->edges[n]).node1=v;
00081 (EdgeList->edges[n]).node2=y;
00082
00083
00084 ind = graph->vertexArray[x].adjListInd;
00085 for(i=0; i< graph->vertexArray[x].degree; i++)
00086 { if (graph->adjArray[ind + i] == y) graph->adjArray[ind+i]=w;}
00087
00088 ind = graph->vertexArray[y].adjListInd;
00089 for(i=0; i< graph->vertexArray[y].degree; i++)
00090 { if (graph->adjArray[ind + i] == x) graph->adjArray[ind+i]=y;}
00091
00092 index = graph->vertexArray[v].next++;
00093 graph->adjArray[ index ] = y;
00094 index = graph->vertexArray[w].next++;
00095 graph->adjArray[ index ] = x;
00096 graph->vertexArray[v].degree++;
00097 graph->vertexArray[w].degree++;
00098 break;
00099
00100 }
00101 }
00102