博客
关于我
Objective-C实现BellmanFord贝尔曼-福特算法(附完整源码)
阅读量:797 次
发布时间:2023-02-17

本文共 1639 字,大约阅读时间需要 5 分钟。

Objective-C ?????-????

???-???????????????????????????????????????????????????????Objective-C????????

????

???-?????????????????????????????????????????????????????????????????????????????(u, v)????????u?v???????v?u?????????v?u??????

????

  • ???

    • ??????????????????????
    • ????????????0??????????
  • ???

    • ???????(u, v)???????????
      • ???????u?v????????u?v????(u, v)????????v?u??????
  • ????

    • ???????????????-????????????????n-1????n???????????????
  • Objective-C ????

    ???????Objective-C??????-???????

    #import 
    @interface Edge : NSObject@property (nonatomic, assign) NSInteger source;@property (nonatomic, assign) NSInteger destination;@property (nonatomic, assign) NSInteger weight;@end@interface BellmanFord : NSObject- (void)initializeDistances:(NSDictionary *)nodes;- (void)relaxEdges:(NSArray *)edges;- (void)bellmanFordAlgorithm:(NSArray *)nodes array:(NSArray *)edges;@end

    ????

    • Edge??????????????????????
    • BellmanFord????????????????????????-????????
      • initializeDistances??????????????
      • relaxEdges???????????????
      • bellmanFordAlgorithm??????-??????????????

    ????

    // ???????NSDictionary *nodes = @{@"source": @"A", @"intermediate1": @"B", @"intermediate2": @"C", @"destination": @"D"};NSArray *edges = @[    @{@"source": @"A", @"destination": @"B", @"weight": -2},    @{@"source": @"B", @"destination": @"C", @"weight": 5},    @{@"source": @"C", @"destination": @"D", @"weight": 3}];// ???????[self initializeDistances:nodes];// ????[self bellmanFordAlgorithm:nodes array:edges];// ????for (NSString *node in nodes) {    NSLog(@"%s?????? %d", node, [distances[node] intValue]);}

    ??

    ???-???????????????????????????????????????????????????Objective-C?????

    转载地址:http://sdnfk.baihongyu.com/

    你可能感兴趣的文章
    Nginx + uWSGI + Flask + Vhost
    查看>>
    Nginx Location配置总结
    查看>>
    Nginx 动静分离与负载均衡的实现
    查看>>
    Nginx 反向代理解决跨域问题
    查看>>
    Nginx 反向代理配置去除前缀
    查看>>
    nginx 后端获取真实ip
    查看>>
    Nginx 学习总结(17)—— 8 个免费开源 Nginx 管理系统,轻松管理 Nginx 站点配置
    查看>>
    nginx 常用配置记录
    查看>>
    Nginx 我们必须知道的那些事
    查看>>
    Nginx 的 proxy_pass 使用简介
    查看>>
    Nginx 的配置文件中的 keepalive 介绍
    查看>>
    nginx 配置 单页面应用的解决方案
    查看>>
    nginx 配置~~~本身就是一个静态资源的服务器
    查看>>
    Nginx下配置codeigniter框架方法
    查看>>
    nginx添加模块与https支持
    查看>>
    Nginx的Rewrite正则表达式,匹配非某单词
    查看>>
    Nginx的使用总结(一)
    查看>>
    Nginx的是什么?干什么用的?
    查看>>
    Nginx访问控制_登陆权限的控制(http_auth_basic_module)
    查看>>
    nginx负载均衡的五种算法
    查看>>