Originally Posted by

**laserlight**
It might be helpful to post the program demonstrating what you have tried. I don't understand what you mean by "lose sight of the contiguous node".

Since you're representing the matrix as a vector of linked lists, I guess that you're dealing with a sparse matrix?

What I mean by it is that when you edit the matrix, you go to the N node in the first row, then change it and make it point to the N-1 node in the second row, then go to the N-1 node in the second row and make it point to the N-2 node in the third row, etc.

But after doing that, you cannot acces what's left after the diagonal (to the right of the diagonal), because the pointers are now not pointing 'forward' anymore.

I'm sorry, i have a hard time explaining it if it isn't graphically.

Anyway, it is a vector of singly linked lists, all of the same size, thus could be seen as a square matrix with n,m >= 2m where m = 1,...,M (even numbers).

Ive a matrix VL that looks like:

Code:

[ ]--->[1| ]--->[2|\]
[ ]--->[3| ]--->[4|\]

I want to print change the pointers and make it like a 'sand-clock' so that going through the list yields:

Code:

1 -> 2 -> 3 -> 4 -> 1 -> 2 -> .... (indefinietely)

Code:

Code:

int main(void)
{
int i, j, value;
lista_t VL[CANTIDAD];
for(i = 0; i < CANTIDAD; i++)
{
VL[i] = NULL;
for(j = 0; j < CANTIDAD; j++)
{
printf("Ingresar valor fila %d: \n", i+1);
scanf("%d", &value);
push(&(VL[i]), value);
}
}
diagonalizar(VL);
return EXIT_SUCCESS;
}
void diagonalizar(lista_t VL[])
{
int i = 0;
for(i = 0; i < 2; i++)
{
anexar(VL, i);
}
}
void anexar(lista_t VL[], int i)
{
int j;
lista_t temp;
/* i = 0 indicates annexing diagonally donwards <V; i = 1 indicates annexing diagonally upwards <^*/
if(!i)
{
for(j = 0; j < (CANTIDAD-1); j++)
{
temp = run(VL, j, CANTIDAD-j);
temp->sig = run(VL, j+1, CANTIDAD-j-1);
}
} else {
for(j = CANTIDAD-1; j > 0; j--)
{
temp = run(VL, j, j+1);
temp->sig = run(VL, j-1, j);
}
}
}
lista_t run(lista_t VL[], int fila, int cant)
{
lista_t temp = VL[fila];
int i;
for(i = 0; i < (cant-1); i++)
{
temp = temp->sig;
}
return temp;
}