Stack and Queue in Lists Posted on February 4, 2008 by sathyz Ruby lists: li = [1,2,3,4] use li as stack, li.push(5) [1,2,3,4,5] li.pop 5 li [1,2,3,4] use li as queue, li.shift 1 li [2,3,4] li.unshift(0) [0,2,3,4] Blogged with Flock Tags: ruby Share this:FacebookLike Loading... Related
I notice one thing. In the queue example you have given, both insertions and deletions seem to be happening in the same end ? Both the examples are stacks and not a queue. PS: i know this is a very old post. chumma commenting 🙂 Reply ↓
I notice one thing. In the queue example you have given, both insertions and deletions seem to be happening in the same end ? Both the examples are stacks and not a queue.
PS: i know this is a very old post. chumma commenting 🙂
Oops, didn’t notice 🙂