Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 808657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:35:51+00:00 2026-05-15T00:35:51+00:00

What are some clever (not ordinary) ways of implementing data structures in C, and

  • 0

What are some clever (not ordinary) ways of implementing data structures in C, and what are some data structures that should be used more often?

For example, what is the most effective way (generating minimal overhead) to implement a directed and cyclic graph with weighted edges in C?
I know that we can store the distances in an array as is done here, but what other ways are there to implement this kind of a graph?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T00:35:52+00:00Added an answer on May 15, 2026 at 12:35 am

    Answering your first question, I recommend to encapsulate your structures using opaque pointers (a.k.a Handles).

    For example, you may declare a handle to a linked list (here MS-like naming):

    typedef struct linked_list_t* HLINKEDLIST;
    

    We assume that linked_list_t is a generic one (composed of void pointers).

    This way you can hide what a “handle” to a linked list is, or in what form is implemented (information hiding):

    HLINKEDLIST LinkedListCreate();
    LinkedListAdd(LLELEMENT v);
    LinkedListCopy(HLINKEDLIST dst, const HLINKEDLIST src);
    

    Handle subtypes are also commonly defined, such as PHLINKEDLIST (pointer to a linked list handle).

    Related types can also be defined for convenience (and to use the limited information hiding available in C). e.g: the linked list element type can be defined as

    typedef void* LLELEMENT;
    

    There are good books on Data Structures in C to check. This is good: http://www.amazon.com/Interfaces-Implementations-Techniques-Creating-Reusable/dp/0201498413

    Also note that LLELEMENT is actually compatible with void* so if you are defining other type def as:

    typedef void* SYSTEMDATA;
    

    SYSTEMDATA is compatible with LLELEMENT, so the compiler won’t complain on:

    int QuerySystemData(SYSTEMDATA* sd);
    

    and calling:

    QuerySystemData(lle);
    

    where lle is of type LLELEMENT.

    This type checking can be enforced encapsulating simple members in structs. If I don’t remember bad, declaring STRICT in a program using windows.h causes handles to be type-safer (incompatible between). Definitions like the following are common:

    typedef struct __HWND 
    { 
    int __handle; 
    } __HWND; 
    
    typedef __HWND* HWND; 
    

    If the simpler definitions were:

    typedef int HWND;
    typedef int HBITMAP;
    

    The two handles would be type compatible and interchangeable on functions expecting to work with windows and functions expecting to work with bitmaps (potential horrible bugs).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.