Skip to content

muhhae/c-data-structure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Here's a well-structured and professional description for your project: (hehe :v)


Type-Safe Generic Linked List in C

This project implements a type-safe, generic doubly linked list in C using macros to generate specialized list structures and functions for different data types. Unlike traditional void*-based generic lists, this approach ensures strong type safety while maintaining flexibility.

Key Features

Type Safety – Prevents type mismatches by generating unique list types for each data type.
Automatic Function Generation – Macros create optimized list operations (LPush, RPush, LPop, RPop, At).
Efficient Memory Management – Supports custom deallocation functions for pointer-based elements.
Bidirectional Traversal – Doubly linked list structure enables fast access from both ends.
Optimized Indexing – Smart selection of forward or backward traversal for At() lookup.

Why This Approach?

  • Avoids void* pitfalls – No need for manual type casting when accessing values.
  • More readable and maintainable – Each list has well-defined operations for its type.
  • Better performance – No runtime type checks; everything is resolved at compile time.

Example Usage

DefineLinkedList(int);  // Generates int-specific list

int main() {
    list_int_t myList = CreateList_int();
    myList.LPush(&myList, 42);
    int *value = myList.At(&myList, 0);
    printf("Value: %d\n", *value);  // Output: 42
}

Would you like me to refine any part of this? 🚀 (hehe :v)

About

Type-Safe Generic Linked List in C

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages