ソートされたリンクリスト関数を再帰的に書くことを試みてきました。誰もが私を助けることができますか?私はその機能でどこにも行きません。私はC++でソートされたリンクリスト関数を再帰的に書くことを試みてきました
void LinkedList::insertRecurcive(Node* head, int data)
{
if (head == NULL || !(head->Data < data))
{
head->next = new Node;``
head->next->Data = data;
head->next->next = NULL;
}
else
insertRecurcive(head->next, data);
}
void LinkedList::insert(int data)
{
insertRecurcive(head, data);
}
ここで難しいのは、次の 'Node'を再帰して、新しい' Node'を挿入する必要があることを発見したときに、 'next'にリンクできるように、リンクされたリストを維持する。以前の 'Node'の' next'への参照を渡すか、次のノードに再帰する前に次の 'Node'のデータをテストしてください。 – user4581301