A palindrome is a word, phrase, number, or other sequence of characters which reads the same backwards and forwards. Can you determine if a given string, s , is a palindrome?
Things learned in this challenge:
- The attr_accessor method lets you create, read(attr_reader), and write (attr_writer) instance variables all in one step. If we didn’t use it, we would have to write all of this out:
- An array can be a stack or queue by limiting yourself to stack or queue methods (push, pop, shift, unshift). Using push / pop gives LIFO behavior (stack), while using push / shift gives FIFO behavior (queue).
- A stack is a data structure that uses a principle called Last-In-First-Out (LIFO), meaning that the last object added to the stack must be the first object removed from it.At minimum, any stack should be able to perform the following three operations:
- Peek: Return the object at the top of the stack (without removing it).
- Push: Add an object passed as an argument to the top of the stack.
- Pop: Remove the object at the top of the stack and return it.
- A queue is a data structure that uses a principle called First-In-First-Out (FIFO), meaning that the first object added to the queue must be the first object removed from it. You can analogize this to a checkout line at a store where the line only moves forward when the person at the head of it has been helped, and each person in the line is directly behind the person whose arrival immediately preceded theirs.At minimum, any queue should be able to perform the following two operations:
- Enqueue: Add an object to the back of the line.
- Dequeue: Remove the object at the head of the line and return it; the element that was previously second in line is now at the head of the line.