• 贝叶斯网络 未学习前数据结构


    /**
    author: lx
    date 4.11 2011
    biref BN
    */

    #pragma once
    #include
    <string>
    #include
    <map>
    #include
    <vector>
    #include
    <iostream>
    using namespace std;

    typedef pair
    < char, float > inter;

    /* struct of node */
    struct nbnode
    {
    char name[20]; /* name */

    vector
    < inter > nodeprob; /* probility of each node */

    };

    void print_nbnode( struct nbnode* node )
    {
    cout
    << "name is " << node->name << endl;

    int i;
    for ( i = 0; i < (node->nodeprob).size(); i++ )
    {
    cout
    << (node->nodeprob)[i].first << " is " << (node->nodeprob)[i].second << endl;
    }
    }


    #include "rbnetwork.h"
    #include
    <stdlib.h>
    #include
    <string.h>
    #include
    <stdio.h>
    #include
    <iostream>
    #include
    <list>
    #include
    <algorithm>
    using namespace std;

    int main( void )
    {
    int n;
    list
    < struct nbnode* > listnode;

    cout
    << "请输入参数个数!" << endl;
    cin
    >> n;

    int i;
    for ( i = 0; i < n; i++ )
    {
    struct nbnode* node = ( struct nbnode* )malloc( sizeof(struct nbnode ) );
    switch( i )
    {
    case 0:
    {
    strcpy( node
    ->name, "a" );

    inter int1, int2;
    int1.first
    = 'f';
    int1.second
    = 0.4f;
    int2.first
    = 't';
    int2.second
    = 0.6f;

    (node
    ->nodeprob).push_back( int1 );
    (node
    ->nodeprob).push_back( int2 );
    listnode.push_back( node ); }
    break;

    case 1:
    {
    strcpy( node
    ->name, "b" );

    inter int1, int2;
    int1.first
    = 'f';
    int1.second
    = 0.5f;
    int2.first
    = 't';
    int2.second
    = 0.5f;

    (node
    ->nodeprob).push_back( int1 );
    (node
    ->nodeprob).push_back( int2 ); listnode.push_back( node );
    }
    break;

    case 2:
    {
    strcpy( node
    ->name, "c" );

    inter int1, int2;
    int1.first
    = 'f';
    int1.second
    = 0.3f;
    int2.first
    = 't';
    int2.second
    = 0.7f;

    (node
    ->nodeprob).push_back( int1 );
    (node
    ->nodeprob).push_back( int2 ); listnode.push_back( node );
    }
    break;

    case 3:
    {
    strcpy( node
    ->name, "d" );

    inter int1, int2;
    int1.first
    = 'f';
    int1.second
    = 0.1f;
    int2.first
    = 't';
    int2.second
    = 0.9f;

    (node
    ->nodeprob).push_back( int1 );
    (node
    ->nodeprob).push_back( int2 ); listnode.push_back( node );
    }
    break;


    default:
    break;
    }

    }
    for_each ( listnode.begin(), listnode.end(), print_nbnode );
    cout
    << endl;

    return 0;
    }

  • 相关阅读:
    每日一道面试题-02
    JAVA获取对象的四种方式
    每日一道面试题-01
    MD5算法原理浅谈
    JAVA--时间格式转换
    数据库-union和union all
    Struts1和Struts2的区别
    Java定时器Timer
    webView调试
    webView和js交互规范
  • 原文地址:https://www.cnblogs.com/lxgeek/p/2012821.html
Copyright © 2020-2023  润新知