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

后端 未结 8 1677
心在旅途
心在旅途 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 08:55

    Use a linked list. Maintain separate pointers for the head and tail. Pop from the head of the list, push onto the tail. If you want it circular, just make sure the new tail always points to the head.

    I can understand why you might want to implement a FIFO using a linked list, but why make it a circular list?

提交回复
热议问题