- #1
evinda
Gold Member
MHB
- 3,836
- 0
Hello! (Wave)
I have to write a recursive algorithm, that, given a list in descending order with $M$ elements, creates a new list, that contains the element of the list in ascending order. The list is singly linked and we are given a pointer that shows to the first element of the list.
That's what I have tried:
Could you tell me if it is right? (Thinking)
I have to write a recursive algorithm, that, given a list in descending order with $M$ elements, creates a new list, that contains the element of the list in ascending order. The list is singly linked and we are given a pointer that shows to the first element of the list.
That's what I have tried:
Code:
Node *Ch(Node *L1){
if (L1.next!= NULL)
Ch(L1.next)
// Create a new node with value L1.data and the next field is NULL
// then we add this node to the List L2
return L2;
}
Could you tell me if it is right? (Thinking)