
[C] 纯文本查看 复制代码 #include "list_menu.h"
Node_T *head, *son,*bro,*temp,*dirnow;
Node_T *creat_father(uint8_t *str,void (*f)(void))
{
Node_T *temp = NULL;
temp = (Node_T *)malloc(sizeof(Node_T));
if (temp == NULL)
{
return NULL;
}
// temp->father = temp;
temp->father = NULL;
temp->brother_up = NULL;
temp->brother_dw = NULL;
temp->son = NULL;
temp->str = str;
temp->f=f;
// printf("creat_father succeed\r\n");
// printf("%s\t\t%x\r\n", temp->str, temp);
return temp;
}
Node_T *creat_brother(Node_T *brother, uint8_t *str,void (*f)(void))
{
Node_T *temp = NULL;
Node_T *temp_1 = brother;
temp = (Node_T *)malloc(sizeof(Node_T));
if (temp == NULL)
{
return NULL;
}
temp->father = temp_1->father;
while (temp_1->brother_dw != NULL)
{
temp_1 = temp_1->brother_dw;
}
temp_1->brother_dw = temp;
temp->brother_up = temp_1;
temp->brother_dw = NULL;
temp->son = NULL;
temp->str = str;
temp->f=f;
// printf("creat_brother succeed\r\n");
// printf("%s\t\t%x\r\n", temp->str, temp);
return temp;
}
Node_T *creat_son(Node_T *father, uint8_t *str,void (*f)(void))
{
Node_T *temp = NULL;
Node_T *temp_1 = father;
temp = (Node_T *)malloc(sizeof(Node_T));
if (temp == NULL)
{
return NULL;
}
temp->father = temp_1;
temp_1->son = temp;
temp->son = NULL;
temp->brother_dw = NULL;
temp->brother_up = NULL;
temp->str = str;
temp->f=f;
// printf("creat_son succeed\r\n");
// printf("%s\t\t%x\r\n", temp->str, temp);
return temp;
}
void list_menu_int(void)
{
head=creat_father("menu",NULL);
son=creat_son(head,"item-1",NULL);
bro=creat_brother(son,"item-2",NULL);
creat_brother(bro,"item-3",NULL);
creat_son(son,"item1-1-1",NULL);
}
[C] 纯文本查看 复制代码 typedef struct Node
{
struct Node *father;
struct Node *brother_up;
struct Node *brother_dw;
struct Node *son;
char *str;
void (*f)(void);
} Node_T;
按上述进行初始化后,在MDK变量观察到每个节点的结构都像第一张图一样,有多个成员。
|