How do I implement a circular list (ring buffer) in C?

后端 未结 8 1674
心在旅途
心在旅途 2020-12-02 08:40

How do I implement a circular list that overwrites the oldest entry when it\'s full?

For a little background, I want to use a circular list within GWT; so using a 3

8条回答
  •  被撕碎了的回忆
    2020-12-02 09:00

    Use an array and keep a variable P with the first available position.

    Increase P every time you add a new element.

    To know the equivalent index of P in your array do (P % n) where n is the size of your array.

提交回复
热议问题