In his programms (Part 5) he refers to "graph.h"
On the website, I found an ftp Server with those files on it:
ftp://ftp.cs.princeton.edu/pub/cs226/map/c/
Now, I downloaded graph.h, graph.c, point.h, point.c, pqindex.h, pqindex.c from there.
I opened these in Dev-C++, and tried to compile "graph.c" but I get multiple errors saying "undefined reference to /something/ "
Am I not meant to compile graph.c? Do I need a different compiler?
The functions which it claims are undefined all seem to be defined in the downloaded files. They are all in the same directory (Desktop). Does Dev-C++ want them somewhere else?
EDIT:
Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- #include "GRAPH.h"
- #include "point.h"
- #include "pqindex.h"
- int main(){
- getchar();
- return 0;
- }
Expand|Select|Wrap|Line Numbers
- #include <stdlib.h>
- #include "GRAPH.h"
- "This code is from "Algorithms in C, Third Edition,"
- by Robert Sedgewick, Addison-Wesley, 2002."
- typedef struct node *link;
- struct node { int v; link next; };
- struct graph { int V; int E; link *adj; };
- link NEW(int v, link next)
- { link x = malloc(sizeof *x);
- x->v = v; x->next = next;
- return x;
- }
- Graph GRAPHinit(int V)
- { int v;
- Graph G = malloc(sizeof *G);
- G->V = V; G->E = 0;
- G->adj = malloc(V*sizeof(link));
- for (v = 0; v < V; v++) G->adj[v] = NULL;
- return G;
- }
- void GRAPHinsertE(Graph G, Edge e)
- { int v = e.v, w = e.w;
- G->adj[v] = NEW(w, G->adj[v]);
- G->adj[w] = NEW(v, G->adj[w]);
- G->E++;
- }
- int GRAPHedges(Edge a[], Graph G)
- { int v, E = 0; link t;
- for (v = 0; v < G->V; v++)
- for (t = G->adj[v]; t != NULL; t = t->next)
- if (v < t->v) a[E++] = EDGE(v, t->v);
- return E;
- }