Sparse Array in C! How accomplish it? Can I alloc only parts of an array?

前端 未结 2 2015
无人及你
无人及你 2020-12-20 03:36

The first question is: \"How I do a simple sparse array in C (with one dimension only)?\" {with my own hands, without libraries.}

And the last one: \"Can I allocate

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-20 04:35

    It is not uncommon to implement these in linked structures of one kind or another. In one dimension you can simple generate a linked list of occupied regions, and I've discussed a two dimensional implementation in another context before.

    You do lose O(1) access time this way, but the win on space can be considerable if the structure really is sparse.

提交回复
热议问题