博客
关于我
Objective-C实现BellmanFord贝尔曼-福特算法(附完整源码)
阅读量:794 次
发布时间: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/

    你可能感兴趣的文章
    npm run build报Cannot find module错误的解决方法
    查看>>
    npm run build部署到云服务器中的Nginx(图文配置)
    查看>>
    npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
    查看>>
    npm start运行了什么
    查看>>
    npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
    查看>>
    NPM使用前设置和升级
    查看>>
    npm入门,这篇就够了
    查看>>
    npm切换到淘宝源
    查看>>
    npm前端包管理工具简介---npm工作笔记001
    查看>>
    npm和yarn清理缓存命令
    查看>>
    npm和yarn的使用对比
    查看>>
    npm学习(十一)之package-lock.json
    查看>>
    npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
    查看>>
    npm的常用配置项---npm工作笔记004
    查看>>
    npm的问题:config global `--global`, `--local` are deprecated. Use `--location=global` instead 的解决办法
    查看>>
    npm配置安装最新淘宝镜像,旧镜像会errror
    查看>>
    npm错误Error: Cannot find module ‘postcss-loader‘
    查看>>
    NPOI之Excel——合并单元格、设置样式、输入公式
    查看>>
    NPOI利用多任务模式分批写入多个Excel
    查看>>
    NPOI在Excel中插入图片
    查看>>