Thanks for the response Paul.
I have to compare the performance using STL and dont using it, so in this case i can't use any container.
You're right about calling the variable "vector". I'll change it.
Here is the code:
Thank you again.Code:void Start(Triangle &t){ t.nrows=0; t.positions=new vPos; } void FreeT(Triangle &t){ if(t.positions){ delete [] t.positions->vector; delete [] t.positions->pos; delete [] t.positions; t.positions=0; } } void AddRow(Triangle &t){ t.nrows++; if(t.nrows==1){ t.posiciones->vector=new int; t.posiciones->pos=&t.posiciones->vector; } else Resize(t, GetNElements(t)); } void Resize(Triangle &t, int n){ vPos *aux=new vPos; aux->pos=new int*[t.nrows]; aux->vector=new int[n]; for(int i=0; i<n; i++) aux->vector[i]=t.positions->vector[i]; for(int j=0; j<t.nrows; j++) aux->pos[j]=&(aux->vector[GetptrPos(j)]); delete [] t.positions->vector; delete [] t.positions->pos; delete t.positions; t.positions=aux; } int GetptrPos(int n){ --------------------------------------------------------- |1|-|2, 3|-|4, 5, 6|-|7, 8, 9, 10| - |11, 12, 13, 14, 15| --------------------------------------------------------- ^ ^ ^ ^ ^ ptr1 ptr2 ptr3 ptr4 ptr5 return n*(n+1)/2; }




Reply With Quote
