[英]How can I advance in a copy of a linked list without changing the original
So my question is, how can I advance in a copy of a linked list without changing the original list.所以我的问题是,如何在不更改原始列表的情况下推进链接列表的副本。 I kinda understand why this happens I just don't know a way to make it not happen.我有点明白为什么会发生这种情况,我只是不知道如何让它不发生。
This is what I've done and when I call another function that uses these lists they don't exist.这就是我所做的,当我调用另一个使用这些列表的 function 时,它们不存在。
typedef struct _edgeList
{
int target;
char* tCity;
char* country;
int population;
float weight;
struct _edgeList *next;
} EdgeList;
typedef struct _collisionList
{
int id;
char *city;
char* country;
int population;
EdgeList *edges;
struct _collisionList *next;
} CollList;
void CityWithMostTargets(CollList** hash)
{
CollList** aux = hash;
int i = 0;
int edges = 0;
int major = 0;
char* city;
for(i = 0; i < HASH_SIZE; i++)
{
while(aux[i])
{
if(aux[i]->edges)
{
edges = CountEdges(hash[i]->edges);
}
if(edges > major)
{
major = edges;
city = strdup(hash[i]->city);
}
if(!aux[i]->next)
break;
aux[i] = aux[i]->next;
}
}
aux = hash;
printf("City: %s\nNumber of edges: %d", city, major);
getchar();
}
You can define another variable to hold the value of aux[i]
that you want to work with.您可以定义另一个变量来保存要使用的aux[i]
的值。
for(i = 0; i < HASH_SIZE; i++)
{
CollList* a = aux[i];
while (a)
{
// etc.
and replace the other uses of aux[i]
within that loop to use a
.并在该循环中替换aux[i]
的其他用途以a
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.