本文共 1639 字,大约阅读时间需要 5 分钟。
Objective-C ?????-????
???-???????????????????????????????????????????????????????Objective-C????????
???-?????????????????????????????????????????????????????????????????????????????(u, v)????????u?v???????v?u?????????v?u??????
???
???
????
???????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
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/