"HR30 Day 18: Queues and Stacks"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 3개는 보이지 않습니다)
9번째 줄: 9번째 줄:
==Java==
==Java==
{{참고|HR30 Day 18: Queues and Stacks/Java}}
{{참고|HR30 Day 18: Queues and Stacks/Java}}
<source lang='Java'>
<syntaxhighlight lang='Java'>
public class Solution {
public class Solution {
     // Write your code here.
     // Write your code here.
26번째 줄: 26번째 줄:
         return queue.remove();
         return queue.remove();
     }
     }
</source>
</syntaxhighlight>


==PHP==
==PHP==
{{참고|HR30 Day 18: Queues and Stacks/PHP}}
{{참고|HR30 Day 18: Queues and Stacks/PHP}}
<source lang='PHP'>
<syntaxhighlight lang='PHP'>
</source>
class Solution {
    // Write your code here
    private $stack = [];
    private $queue = [];
    function pushCharacter($ch) {
        array_push($this->stack, $ch);
    }
    function enqueueCharacter($ch) {
        array_push($this->queue, $ch);
    }
    function popCharacter() {
        return array_pop($this->stack);
    }
    function dequeueCharacter() {
        return array_shift($this->queue);
    }
}
</syntaxhighlight>
<syntaxhighlight lang='php'>
class Solution {
    // Write your code here
    private $stack;
    private $queue;
    function __construct() {
        $this->stack = new SplStack();
        $this->queue = new SplQueue();
    }
    function pushCharacter($ch) {
        $this->stack->push($ch);
    }
    function enqueueCharacter($ch) {
        $this->queue->enqueue($ch);
    }
    function popCharacter() {
        return $this->stack->pop();
    }
    function dequeueCharacter() {
        return $this->queue->dequeue();
    }
}
</syntaxhighlight>
 
==Python==
{{참고|HR30 Day 18: Queues and Stacks/Python}}
<syntaxhighlight lang='Python'>
class Solution(object):
    # Write your code here
    def __init__(self):
        self.stack = []
        self.queue = []
    def pushCharacter(self, ch):
        self.stack.append(ch)
    def enqueueCharacter(self, ch):
        self.queue.insert(0, ch)
    def popCharacter(self):
        return self.stack.pop()
    def dequeueCharacter(self):
        return self.queue.pop()
</syntaxhighlight>

2021년 7월 31일 (토) 10:34 기준 최신판

1 개요[ | ]

HR30 Day 18: Queues and Stacks
해커랭크 30 Days of Code
문제 풀이
10-19 Day e
HR30 Day 10: Binary Numbers

HR30 Day 11: 2D Arrays

HR30 Day 12: Inheritance

HR30 Day 13: Abstract Classes

HR30 Day 14: Scope

HR30 Day 15: Linked List

HR30 Day 16: Exceptions - String to Integer

HR30 Day 17: More Exceptions

HR30 Day 18: Queues and Stacks

HR30 Day 19: Interfaces

2 Java[ | ]

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

3 PHP[ | ]

class Solution {
    // Write your code here
    private $stack = [];
    private $queue = [];
    function pushCharacter($ch) {
        array_push($this->stack, $ch);
    }
    function enqueueCharacter($ch) {
        array_push($this->queue, $ch);
    }
    function popCharacter() {
        return array_pop($this->stack);
    }
    function dequeueCharacter() {
        return array_shift($this->queue);
    }
}
class Solution {
    // Write your code here
    private $stack;
    private $queue;
    function __construct() {
        $this->stack = new SplStack();
        $this->queue = new SplQueue(); 
    }
    function pushCharacter($ch) {
        $this->stack->push($ch);
    }
    function enqueueCharacter($ch) {
        $this->queue->enqueue($ch);
    }
    function popCharacter() {
        return $this->stack->pop();
    }
    function dequeueCharacter() {
        return $this->queue->dequeue();
    }
}

4 Python[ | ]

class Solution(object):
    # Write your code here
    def __init__(self):
        self.stack = []
        self.queue = []
    def pushCharacter(self, ch):
        self.stack.append(ch)
    def enqueueCharacter(self, ch):
        self.queue.insert(0, ch)
    def popCharacter(self):
        return self.stack.pop()
    def dequeueCharacter(self):
        return self.queue.pop()
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}