Git Product home page Git Product logo

stage1-module4-collections-task4-queue's Introduction

Tasks

1. PriorityQueue creator

Implement the program which gets two List<String> and merged them into PriorityQueue<String> alphabetically in reverse order.

public class PriorityQueueCreator {
    public PriorityQueue<String> createPriorityQueue(List<String> firstList, List<String> secondList) {
    }
}

Input

firstList = ["Java", "PriorityQueue", "class"]
secondList = ["It", "is", "different", "from", "standard", "queues", "where", "FIFO"]

Output

["where", "standard", "queues", "is", "from", "different", "class",  "PriorityQueue", "Java", "It", "FIFO"]

2. ArrayDeque creator

Two players have two Queue<Integer> of cards with the same even sizes(>=2). They want to combine all the cards together into an ArrayDeque<Integer> according to the following rule.

First, both take turns adding two cards to the ArrayDeque<Integer>. Then, with each move, the player:

  • takes the top card from the ArrayDeque<Integer> and adds this card to the end of his Queue<Integer>
  • then puts two cards from the beginning of his Queue<Integer> into the ArrayDeque<Integer>.

The moves go until the both players' Queue<Integer> of cards are not empty.

Implement the program which gets two Queue<Integer> and creates ArrayDeque<Integer> in accordance with the rules of the game.

public class ArrayDequeCreator extends PriorityQueue<String> {
    public ArrayDeque<Integer> createArrayDeque(Queue<Integer> firstQueue, Queue<Integer> secondQueue) {
    }
}

Input

firstQueue = [1, 5, 7, 6]
secondQueue = [2, 5, 8, 3]

Output

[1, 5, 2, 7, 8, 5, 6, 3]

3. Dish order determiner

On the round table stands numberOfDishes dishes numbered in ascending order from 1 to numberOfDishes. A man wants to try all the dishes according to the following rule:

  • He will eat every everyDishNumberToEat dish until he has eaten everything.

Implement the program which gets number of dishes as parameter numberOfDishes, dish number to eat as parameter everyDishNumberToEat and returns a List<Integer> of dish numbers in which all dishes will be eaten.

public class DishOrderDeterminer {
    public List<Integer> determineDishOrder(int numberOfDishes, int everyDishNumberToEat) {
        Queue<Integer> queue;
    }
}

Example

Input

numberOfDishes = 10
everyDishNumberToEat = 3

dishes: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Output

[3, 6, 9, 2, 7, 1, 8, 5, 10, 4]

stage1-module4-collections-task4-queue's People

Contributors

hopenadyahope avatar alehdrazdou avatar symbatdeveloper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.