我遇到了一个问题,我尝试在链表上使用while循环。 我有两个链表,分别为temp
和。我正在使用while循环来执行任务while(temp != NULL)
。要继续在每个循环中,我将分配temp = temp->link
。但是,这段代码不能编译。我意识到递归函数可能是一个解决方案,但函数实际上更复杂,我不认为递归会是一个好主意。顺便说一句,已经是一个建立链接列表。提前致谢!C使用while循环链表
P.S.这是作业的一部分。
temp = graph->link;
while(temp!=NULL){
if(stack->link == NULL){
stack->link = (node_pointer)malloc(sizeof(graph));
stack->link->weight = temp->weight;
stack->link->vertex = temp->vertex;
}
temp = temp->link; //Here is the problem.
}
编辑:
堆栈和图表是链表的两个阵列:
typedef struct node *node_pointer;
struct node{
int vertex;
int weight;
int visited;
struct node *link;
};
node_pointer graph[50];
node_pointer stack[50];
node_pointer temp;
什么是错误信息? –
您能否至少向我们展示temp,stack和graph的定义。如果你添加编译器错误,它会有所帮助。 – dwalter
'但是,这段代码不能编译。 “我不明白这个说法。你没有任何的麻烦问题。 – banuj