Day 18: Queues and Stacks (30 Days of Code)

Input Format

You do not need to read anything from stdin. The locked stub code in your editor reads a single line containing string s. It then calls the methods specified above to pass each character to your instance variables.

Output Format

You are not responsible for printing any output to stdout.
If your code is correctly written and  is a palindrome, the locked stub code will print ;The word, “+s+”, is a palindrome.” otherwise, it will print  “The word, “+s+”, is not a palindrome.”

Sample Input

racecar

Sample Output

The word, racecar, is a palindrome. 

Solution:

1)Javascript

function Solution(){
   //Write your code here
   var stack =  [];
   var queue = [];
 this.pushCharacter=function(char){
       stack.push(char);
   }
 this.enqueueCharacter = function(char){
       queue.push(char);
   }
 this.popCharacter = function(){
       return stack.pop();
   }
 this.dequeueCharacter = function(){
       return queue.shift();
   }
 }