struct Numero { ishort num; Number * next; };
ishort array[3];
array[0] = grid1;
array[1] = grid2;
array[2] = grid3;
array[3] = grid4;
ishort i = 0;
Numero *n;
Numero *t;
Numero *h;
//lista circular
while(i <= 3)
{
n = new Numero;
n->num = array[i];
if(i == 0)
{t = n;
h = n;}
t->next = n; //linka com n
t = t->next; //aponta pra n
if(i == 3)
{
n->next = h;
n = n->next;
}
i++;
}
i = 0;
while(i <= 3)
{
cout << h->num << ", ";
h = h->next;
i++;
}
Simple, I created a function that takes 4 values (ex: 3, 5, 7 and 8) and assigns them to an array of 4 elements, to be stored in a circular list. During the storage loop, when array [i] arrives at time 3, it would receive array [3].
But at the time of the 2nd printing loop, it prints 3, 5, 7, and 0. Being that I did everything right. I do not know what I'm doing anymore, any help? Thanks!