链表.简单的链表节点构建

/*编程环境WIN-TC*/
#include "stdio.h"
#include "conio.h"

#define NODE(name, key_word, help) \
 Node name[1]={{NULL, NULL, NULL, key_word, help}}

typedef struct node
{
    struct node *next;    /*兄弟节点*/
    struct node *child;  /*子节点*/
    struct node *parent; /*父节点*/

    const char *key_word;
    const char *help;
}Node;

/*各节点关联构成链表*/

int node_add(Node *mynode, Node *parent)
{
    if(mynode == NULL || parent == NULL)
        return 0;
    mynode->parent = parent;   
    mynode->next = parent->child;
    parent->child = mynode;
    return 1;
}

main()
{

    /*父子兄弟节点测试*/
    NODE(node_modem, "modem", "GPRS modem");
    NODE(node_modem_test, "modem test", "GPRS modem test");
    NODE(node_modem_run, "modem run", "GPRS modem rum");
    NODE(node_modem_go, "modem go", "GPRS modem go");
    node_add(node_modem_test, node_modem);
    node_add(node_modem_run, node_modem);
    node_add(node_modem_go, node_modem);
    printf("%s",node_modem->child->next->key_word);

    getch();
}

更多详细信息请查看 java教程网 http://www.itchm.com/forum-59-1.html

你可能感兴趣的:(编程技巧)