anyone know what is wrong? it keep getting freeze.... i need to finish within 2
ID: 3768600 • Letter: A
Question
anyone know what is wrong? it keep getting freeze.... i need to finish within 2 hour please help me
typedef struct node {
ElemType val;
struct node *next;
} NODE;
struct list_struct {
NODE *front;
NODE *back;
};
void lst_merge_sorted(LIST *a, LIST *b){
NODE *nodeA = a->front;
NODE *nodeB = b->front;
if (nodeB == NULL) return;
if(nodeA->val <= nodeB->val) {
NODE *tmp = nodeA->next;
b->front = nodeB->next;
nodeA->next = nodeB;
nodeB->next = tmp;
a->front = nodeB;
} else {
NODE *tmp1 = b->front;
b->front = nodeB->next;
tmp1 -> next = a->front;
}
lst_merge_sorted(a, b);
}
Explanation / Answer
i m not sure but try with this
extern void lst_merge_sorted(LIST *a, LIST *b);
void lst_merge_sorted(LIST *a, LIST *b){
NODE *aCurr,*bCurr,*aTemp,*bTemp;
aCurr = a->front;
bCurr = b->front;
aTemp = a->front;
bTemp = b->front;
int aLength = 2, bLength = 2;
while(aCurr->next != NULL){
aLength++;
aCurr = aCurr->next;
}
while(bCurr->next != NULL)
{
bLength++;
bCurr = bCurr->next;
}
int i,j;
for (i = 0; i < aLength; i++){
for(j = 0; j < bLength; j++){
if (bTemp->val < aTemp->val){
bTemp->next = aTemp->next;
aTemp->next = bTemp;
}
bTemp = bTemp->next;
}
aTemp = aTemp->next;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.