私は2つのリンクされたリストを取って一緒に置くことになっている関数を持っています。
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()関数は、structノードにデータを追加するだけです。
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;
};