#### Archived

This topic is now archived and is closed to further replies.

# Shifting arrays...

This topic is 5658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''m finally almost done with some semantic network code I''ve been working on. I know the code compiles fine but I''m not sure if it will shift everything properly... Would someone just look it over for me?

//Clean clean all nodes and links that are slated  for demolition

void semNet::clean()
{
unsigned short i, j;                                                           //Declare our counters

for (i = 0; i < nU; i++)                                                       //Clean the nodes

{
//If one of them is slated for demolition, kill the link

if ((net[i].flags & 1) == 1)
{
for (j = i + 1; j < nU; j++)                                 //Move the other links down

{
net[j - 1].knowledge = net[j].knowledge;
net[j - 1].pos = net[j].pos;
net[j - 1].lU = net[j].lU;
net[j - 1].flags = net[j].flags;

for (unsigned char i = 0; i < net[nU].lU; i++)
{
}
}
nU--;                                                                //Get rid of a node

}
}
}

//Clean all links for all nodes

{
unsigned short i, j, l;                                                        //Declare our counters

for (l = 0; l < nTot; l++)
{
for (i = 0; i < net[l].lU; i++)
{
//If one of them is slated for demolition, kill the link

{
for (j = i + 1; j < net[l].lU; j++)                            //Move the other links down

{

}
net[l].lU--;                                                   //Get rid of a link

}
}
}
}

//Clean the links for a certain node

{
unsigned short i, j;                                                           //Declare our counters

for (i = 0; i < net[nN].lU; i++)
{
//If one of them is slated for demolition, kill the link

{
for (j = i + 1; j < net[nN].lU; j++)                                 //Move the other links down

{

}
net[nN].lU--;                                                        //Get rid of a link

}
}
}


##### Share on other sites
I think there''s an error: if an item at index I is deleted,
then item at index I+1 will move at index I (as well as the others, which will shift up). But the for loop will then increment, and process item I+1 (which was the previous I+2 item) leaving the item at I (previously at I+1) unprocessed.

Besides, the code looks ok to me. Why not test it? Perhaps with a log to file, maybe?

• 16
• 11
• 10
• 9
• 49
• ### Forum Statistics

• Total Topics
631392
• Total Posts
2999743
×