ตัวอย่างการเขียนโปรแกรม ของ บัพเฟอร์วงกลม

ตัวอย่างการเขียนโปรแกรมด้วยภาษาไพทอน (Python)

 1 class CircularBuffer: 2     def __init__(self, size): 3         self.size = size 4         self.data = [None]*size 5         self.cur = 0 6  7     def append(self, x): 8         self.data[self.cur] = x 9         self.cur = (self.cur + 1) % self.size10 11 12     def get(self):13         return self.data[self.cur:]+self.data[:self.cur]