Question
C++ How do I write a function that traverse a binary tree and insert items in nodes into a linked list while traversing. I don't
C++
How do I write a function that traverse a binary tree and insert items in nodes into a linked list while traversing. I don't know what I'm doing and its getting worse, been stuck for days, help please! Pretend that I have items stored in my BTNodes.
These are the header files I have.
template
template
} ----------------------------------------------------------------------------------------------------
(Linked List node)
template
};
template
}
-------------------------------------------------------------------------------------
BST.h
class BST { private: int count; BTNode
void insertList2(BTNode
public:
bool insertList(T);
template
}
template
insertList2(root);
return true;
}
-------------------------------------------------------------------------------------------------------
Linked List header
List.h
template
public:
List();
bool List_insert(T);
template
template
if (!tmp) return false; if (empty()) { head = tmp; count++; return true; } count++; if (head->item >= newItem) { tmp->next = head; head = tmp; return true; } pre = head; cur = pre->next; for (; cur != NULL;) { if (cur->item >= newItem) break; pre = cur; cur = cur->next; } tmp->next = cur; pre->next = tmp; return true; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started