Znamená to pseudocode předpokládat nulový založený index?

hlasů
0

Nejsem si jistý, jestli, když píší 1, pokud se jedná o první nebo druhý prvek v poli:

function DouglasPeucker(PointList[], epsilon)
 //Find the point with the maximum distance
 dmax = 0
 index = 0
 for i = 2 to (length(PointList) - 1)
  d = OrthogonalDistance(PointList[i], Line(PointList[1], PointList[end])) 
  if d > dmax
   index = i
   dmax = d
  end
 end

 //If max distance is greater than epsilon, recursively simplify
 if dmax >= epsilon
  //Recursive call
  recResults1[] = DouglasPeucker(PointList[1...index], epsilon)
  recResults2[] = DouglasPeucker(PointList[index...end], epsilon)

  // Build the result list
  ResultList[] = {recResults1[1...end-1] recResults2[1...end]}
 else
  ResultList[] = {PointList[1], PointList[end]}
 end

 //Return the result
 return ResultList[]
end

Například já jsem se provádí to v C ++, takže kde se říká, pro i = 2, bych měl udělat pro int i = 1?

dík

Položena 16/08/2010 v 19:07
zdroj uživatelem
V jiných jazycích...                            


2 odpovědí

hlasů
2

Odhadem, vypadá to, že index 1 je první prvek v poli (jinak se první prvek nikdy indexované kdekoliv). Nejlepší způsob, jak říct s jistotou, je pravděpodobně to vyzkoušet i když :)

Odpovězeno 16/08/2010 v 19:09
zdroj uživatelem

hlasů
1

Je to 1-indexovány. Všimněte si, že řádek:

recResults1[] = DouglasPeucker(PointList[1...index], epsilon)

jakož i:

ResultList[] = {recResults1[1...end-1] recResults2[1...end]}

Oba přístup od začátku seznamu.

Odpovězeno 16/08/2010 v 19:10
zdroj uživatelem

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more