如何在C ++中定义锯齿状数组 [英] how to define jagged array in C++

查看:63
本文介绍了如何在C ++中定义锯齿状数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将以下TSP动态算法转换为C ++,但我遇到了实现这样的数组的问题:D [1 .. n] [V的子集 - {v1}]


i'm trying to translate the below TSP dynamic algorithm into C++ but i'm having problems with implementing an array like this : " D [1 .. n] [subset of V - {v1}] "

void travel (int n,
                           const number W [] [],
                           index P [] [],
                           number & minlength)
{
   index i, j, k;
   number D [1 .. n] [subset of V - {v1}];

   for (i = 2; i <= n; i++)
          D [i] [⊘] = W[i] [1];
   for (k = 1; k <= n - 2; k++)
                for (all subsets A ⊆ V - {v1} containing k vertices)
                          for (i such that i ≠ 1 and vi is not in A){
                            D [i] [A] = minimum (W [i] [j] + D [j] [A - {vj}]);
                                      j: [vj ∊ A
                            P[i] [A] = value of j that gave the minimum;
          }
     D [1] [V - {v1}] = minimum (W[1] [j] + D[j] [V - {v1, vj}]);
                   2 ≤ j ≤ n
    P[1] [V - {v1}] = value of j that gave the minimum;
    minlength = D[1] [V - {v1}];
}

推荐答案

概念语言C ++是面向内存的演进版本。您有权力和负担准确地实现内存访问。它让你有足够的力量在脚下射击自己。 ;-)



这是一个真正的精彩的教程如何完成C ++中的数组访问。
The concept language C++ is very memory oriented evolved. You have the power and the burden to exactly implement the memory access. It gives you the full power to shot yourself in the foot. ;-)

Here is a really nice tutorial how array access in C++ is done.


这篇关于如何在C ++中定义锯齿状数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆