Kruskal算法调试报错求助:C语言ADT图入门遇0xCDCDCDCD问题
Hey there, I’ve been in your shoes debugging ADT graph algorithms before—let’s break down this frustrating error step by step. That 0xCDCDCDCD marker is a dead giveaway, so let’s start there:
What’s up with 0xCDCDCDCD?
If you’re using Visual Studio, that hex value is the debugger’s way of telling you you’re accessing uninitialized heap memory. Your plist->cur pointer is pointing to space that was allocated but never properly set up—so when your code tries to read cur->data or cur->next, it’s grabbing garbage that doesn’t make sense, hence the crash.
Following the error trail
Your call stack points straight to the problem spot:
- Starts in your main function with
ConKruskalMST(&graph) - Moves to
IsConnVertex(pg, edge.v1, edge.v2)(ALGraphKruskal.c line 172) - Fails inside the loop
while (LNext(&(pg->adjList[visitV]), &nextV) == TRUE)(ALGraphKruskal.c line 108)
The issue is the linked list at pg->adjList[visitV]—its cur member was never initialized before LNext tries to use it.
Fixes to try right now
Here are the most common reasons this happens, and how to fix them:
- Don’t skip list initialization: Every linked list in your adjacency list (
adjListarray) needs to be initialized with your list’s setup function (likeLInit). If you allocatedadjListwithmalloc, don’t just stop at allocating memory—loop through each element and run the init function to sethead,cur, andtailto valid values (usuallyNULLor a sentinel node, depending on your ADT design). - Check adjacency list setup: When building your graph, make sure you initialize each vertex’s list before adding edges to it. It’s easy to rush past this step when you’re focused on adding edges, but uninitialized lists will throw exactly this error.
- Audit your
LNextfunction: Take a look at howLNextworks. If it assumescuris already pointing to a valid node (without checking if it’s uninitialized orNULL), that’s a problem. Add a quick check at the start ofLNextto ensure the input list is properly set up before accessing its members. - Use debugger watches: While debugging, add a watch for
pg->adjList[visitV]right before theLNextcall. Ifcurshows up as0xCDCDCDCD, that confirms the list wasn’t initialized. You can then backtrack to find where this list was created without proper setup.
内容的提问来源于stack exchange,提问作者Youngjun

