Lets say I have a node like this
and lets say that i entered 3 nodes (which all have their memory allocated of course) in a list which looks like this:Code:typedef struct node { int data; struct node *next; } Node;
If I enter a number lets say 7, I would like to have a funcntion that enters 7-3 = 4 nodes at the end of the list so when it is done the list looks like this:Code:1. node data = 1 2. node data = 2 3. node data = 3
I'd like to use a loop to do this but it doesn't work at all, it doesn't compile as it breaks on the green line.Code:1. node data = 1 2. node data = 2 3. node data = 3 4. node data = 4 5. node data = 5 6. node data = 6 7. node data = 7
Code:/* NEW NODE */ Node* NewNode(int n) { Node* new = malloc(sizeof(kat)); new->data = n; new->next = NULL; return(new); } /* LAST NODE */ Node* LastNode(Node *head) { Node *temp = head; while (temp != NULL) temp = temp->next; return(temp); } /* ADD NODES */ void AddNodes(Node **head, int n) { Node *last; do { last = LastNode(*poc); Node *new = NewNode(last->data); last->next = new; } while (last->data < n) }



LinkBack URL
About LinkBacks


