屌丝眼中的各种大学专业# Joke - 肚皮舞运动
Q*e
1 楼
抛砖引玉,
struct list_node *
merge2sorted2(struct list_node *a, struct list_node *b)
{
int first_node;
struct list_node *head = NULL;
struct list_node *cur = NULL, *node;
if (a == NULL) return b;
if (b == NULL) return a;
first_node = 1;
while (a || b ) {
if (a && b) {
if (a->data < b->data) {
node = a;
a = a->next;
} else {
node = b;
b = b->next;
}
} else if (a) {
node = a;
a = a->next;
} else {
node = b;
b = b->next;
}
if (first_node) {
head = node;
cur = node;
first_node = 0;
} else {
cur->next = node;
cur = cur->next;
}
}
return head;
}
struct list_node *
merge2sorted2(struct list_node *a, struct list_node *b)
{
int first_node;
struct list_node *head = NULL;
struct list_node *cur = NULL, *node;
if (a == NULL) return b;
if (b == NULL) return a;
first_node = 1;
while (a || b ) {
if (a && b) {
if (a->data < b->data) {
node = a;
a = a->next;
} else {
node = b;
b = b->next;
}
} else if (a) {
node = a;
a = a->next;
} else {
node = b;
b = b->next;
}
if (first_node) {
head = node;
cur = node;
first_node = 0;
} else {
cur->next = node;
cur = cur->next;
}
}
return head;
}