Sort by

recency

|

693 Discussions

|

  • + 0 comments

    code in java 15 class solution {

    ArrayDeque ad1=new ArrayDeque(); //for stack ArrayDeque ad2=new ArrayDeque(); //for queue

    void pushCharacter(char ch)
    {
        ad1.push(ch);
    
    }
    void enqueueCharacter(char ch)
    {
        ad2.add(ch);
    }
    
    
    char popCharacter()
    {
        return (char)ad1.pop();
    }
    
    char dequeCharacter()
    {
        return (char)ad2.poll();
    }
    
    
    
    
    
    public static void main(String[] args) {
    
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        Solution p=new Solution();
        for(int i=0;i<s.length();i++)
        {
            p.pushCharacter(s.charAt(i));
            p.enqueueCharacter(s.charAt(i));
        }
    
        boolean b=true;
        for(int i=0;i<s.length()/2;i++)
        {
            if(p.popCharacter()!=p.dequeCharacter())
            {
                b=false;
                break;
            }
        }
        if(b)
        {
            System.out.println("The word, "+s+", is a palindrome.");
        }
        el
                }se
        {
        System.out.println("The word, "+s+", is not a palindrome.");
        }
    }
    
  • + 0 comments

    def init(self): self.stack = [] self.queue = []

    def pushCharacter(self, char):
        self.stack.append(char)
    
    def enqueueCharacter(self, char):
        self.queue.append(char)
    
    def popCharacter(self):
        if len(self.stack) == 0:
            return None
        return self.top()
        self.stack = self.stack[:-1]
    
    def top(self):
        if len(self.stack) == 0:
            return None
        return self.stack[-1]
    
    def dequeueCharacter(self):
        if len(self.queue) == 0:
            return None
        return self.front()
        self.queue = self.queue[1:]
    
    def front(self):
        if len(self.queue) == 0:
            return None
        return self.queue[0]
    
  • + 0 comments

    Java

    public class Solution {
        // Write your code here.
         Stack<Character> stack = new Stack<>();
        Queue<Character> queue = new LinkedList<>();
        public void pushCharacter(char c)
        {
            stack.push(c);
        }
        public void enqueueCharacter(char c)
        {
            queue.add(c);
        }
        public char popCharacter()
        {
            return stack.pop();
        }
        public char dequeueCharacter()
        {
            return queue.remove();
        }
    
  • + 0 comments

    IMO these challanges are getting easier every week. *Pyhon code: *

    def __init__(self):
            self.queue = []
            self.stack = []
    
        def pushCharacter(self, char):
            self.stack.append(char)
        def enqueueCharacter(self, char):
            self.queue.append(char)
        def popCharacter(self):
            return self.stack.pop(-1)
        def dequeueCharacter(self):
            return self.queue.pop(0)
    
  • + 0 comments
    class Solution:
        # Write your code here
        def __init__(self):
            # We only need one stack/queue buffer
            self.my_buffer = []
            
        def pushCharacter(self, c):
            # Build the buffer here
            self.my_buffer.append(c)
            
        def enqueueCharacter(self, c):
            # Don't bother building a queue
            pass
            
        def popCharacter(self) -> str:
            # Pop the buffer from the end
            return self.my_buffer.pop()
            
        def dequeueCharacter(self) -> str:
            # Pop the buffer from the front
            return self.my_buffer.pop(0)