【发布时间】:2011-10-27 20:41:45
【问题描述】:
我有一个函数应该把两个链表放在一起。
void Append(struct node** aRef, struct node** bRef){
struct node* first = *aRef;
struct node* second = *bRef;
struct node* temp = NULL;
while(first != NULL || second != NULL){
Push(&temp, first->data);
Push(&temp, second->data);
first = first->next;
second = second->next;
}
*aRef = temp;
DeleteList(&second);
}
我想对其进行排序,但是当我用这个替换 while 循环时,我不断收到分段错误:
while(first != NULL || second != NULL){
if(first->data < second->data){
Push(&temp, first->data);
first = first->next;
}
else{
Push(&temp, second->data);
second = second->next;
}
}
Push() 函数只是将一些数据添加到结构节点:
void Push(struct node** headRef, int data){
struct node* new = malloc(sizeof(struct node));
new->data = data;
new->next = *headRef;
*headRef = new;
}
struct node{
int data;
struct node* next;
};
【问题讨论】:
-
我刚刚意识到这甚至不能完全排序列表
标签: c sorting struct linked-list