I'm trying to create a function that will add a node at the end of a linked list. Every time I run it however, I'm getting a runtime error and have no idea where my mistake is. Here's my code:
Edge* append(Edge *head, int origin, int destination, int weight) {
Edge *temp = new Edge;
temp = head;
Edge *node = new Edge;
while (temp->next != NULL){
temp = temp->next;
}
node->vert1 = origin;
node->vert2 = destination;
node->weight = weight;
node->next = NULL;
if (head == 0) {
head = node;
}
else if (head != 0){
node = temp;
}
return head;
}
UPDATE:
Here is the Edge struct:
struct Edge {
int vert1;
int vert2;
int weight;
Edge *next;
};
Here is the main function:
int main(){
Edge *e = append(NULL, 1,4,5);
}