Czy to pseudokod zakładać indeks oparty zero?

głosy
0

Nie jestem pewien, czy kiedy piszą 1, jeżeli jest to pierwszy lub drugi element tablicy:

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

na przykład, jestem wdrożenie tego w C ++, więc gdzie jest napisane dla i = 2, należy zrobić dla int i = 1?

Dzięki

Utwórz 16/08/2010 o 19:07
źródło użytkownik
W innych językach...                            


2 odpowiedzi

głosy
2

Na oko, wygląda na to indeks 1 to pierwszy element tablicy (w przeciwnym razie pierwszy element nie jest indeksowany w dowolnym miejscu). Najlepszym sposobem, aby powiedzieć na pewno, to prawdopodobnie spróbować choć :)

Odpowiedział 16/08/2010 o 19:09
źródło użytkownik

głosy
1

To 1-indeksowane. Zwróć uwagę na linię:

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

jak również:

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

Zarówno dostęp z początku listy.

Odpowiedział 16/08/2010 o 19:10
źródło użytkownik

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