Inserting for a sorted sequence of nodes.
Hey guys I'm a little confused on how I would go about inserting on a sorted sequence of nodes. My logic is off. How would I go about fixing it?
1 2 3 4 5 6 7 8 9
|
void insert(Node *head, EType &val) {
if(!head) throw "Passed NULL to insert";
Node *p = head;
Node *q = head->next;
while (p < q) {
Node *newNodeP = new Node(val, p->next);
p = newNodeP->next;
}
}
|
You're comparing pointers. Compare the values stored in the nodes.
Topic archived. No new replies allowed.