Created
March 5, 2013 16:06
-
-
Save ploubser/5091382 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RoundedQueue | |
| attr_accessor :index | |
| def initialize(base = []) | |
| @queue = base | |
| @index = 0 | |
| end | |
| def get | |
| if @index >= @queue.size - 1 | |
| rv = @queue[@index] | |
| @index = 0 | |
| return rv | |
| else | |
| rv = @queue[@index] | |
| @index += 1 | |
| return rv | |
| end | |
| end | |
| def push(x) | |
| @queue.push(x) | |
| end | |
| def append(x) | |
| if (@index + 1) > @queue.size | |
| @queue.push(x) | |
| else | |
| @queue.insert((@index + 1), x) | |
| end | |
| end | |
| end | |
| a = RoundedQueue.new([1,2,3,4,5]) | |
| while(true) | |
| puts a.get | |
| sleep(0.2) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment