半导体笔试题
Practice
Create a tree, which has h (h>0) layers, and its each node has w(w>0) sub-nodes.Please complete the following incomplete solution.
#include
#include
struct tree{
char info;
p_sub; //link to sub-nodes};
// allocate memory and initiate
void dnode ( struct tree* tmp )
{
= malloc( sizeof (struct tree) );
= 0x41;
= NULL;
}
struct tree *dtree (struct tree* subtree, int height, int width)
{
int i;
if ( !subtree ) //if necessary, allocte memory for subtree
denode(subtree);
if ( height == 1 )
return subtree;
else if ( height == 2 ) {
struct tree *leaf = NULL;
for ( i=0; i
;
leaf = NULL;}
return subtree;}
else {
for ( i=0; i
return subtree;
}
}
main()
{
.........
struct tree *root = NULL;
版权声明:此文自动收集于网络,若有来源错误或者侵犯您的合法权益,您可通过邮箱与我们取得联系,我们将及时进行处理。
本文地址:https://www.gunzhua.com/jiuye/bishi/84805.html