Are Linked Lists in C Similar to Arrays of Structures?
Asked by
CuriousCoder82
I've started learning about algorithms and data structures at my university, and I've been experimenting with linked lists in C. While they can be challenging, I find them quite interesting! This led me to wonder: are linked lists in C similar to arrays of 'classes'? When you create a structure, it's essentially a collection of different data types that you name and can access. Typically, you store these structures in the nodes of a linked list, which also have pointers to the next node. This makes me think that a linked list resembles an array of structures. Is this analogy valid? Am I understanding things correctly, or does this sound off?
Answers
You're definitely on the right track! A class object is indeed a data structure, but remember that a linked list isn't quite like an array. In an array, accessing any element takes the same amount of time due to the way data is organized in memory. Linked lists don't have that predictable layout, so you have to traverse them sequentially.
Reply to this answer
Add your answer
Answers are reviewed before publication.
ThoughtfulLearner21: Thanks for the clarification! Would it be better to think of a linked list as a 'collection' of similar structures, each linked together?