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

31번째 줄: 31번째 줄:
{{참고|HR30 Day 18: Queues and Stacks/PHP}}
{{참고|HR30 Day 18: Queues and Stacks/PHP}}
<source lang='PHP'>
<source lang='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);
    }
}
</source>
</source>

2018년 8월 15일 (수) 16:46 판

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);
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}