chore(i8n,learn): processed translations

This commit is contained in:
Crowdin Bot
2021-02-06 04:42:36 +00:00
committed by Mrugesh Mohapatra
parent 15047f2d90
commit e5c44a3ae5
3274 changed files with 172122 additions and 14164 deletions

View File

@ -1,42 +1,62 @@
---
id: 587d8255367417b2b2512c75
title: 创建循环队列
title: Create a Circular Queue
challengeType: 1
videoUrl: ''
forumTopicId: 301625
dashedName: create-a-circular-queue
---
# --description--
在此挑战中,您将创建一个循环队列。循环队列基本上是一个写入集合末尾的队列,然后开始在集合开头写自己。这种类型的数据结构在某些情况下具有一些有用的应用。例如,循环队列可用于流媒体。队列填满后,新媒体数据就会开始覆盖旧数据。说明这个概念的一个好方法是使用数组:
In this challenge you will be creating a Circular Queue. A circular queue is a queue that writes to the end of a collection then begins overwriting itself at the beginning of the collection. This type of data structure is useful in certain situations. For example, a circular queue can be used for streaming media. Once the queue is full, new media data will overwrite old data.
> \[1,2,3,4,5]
> ^读@ 0
> ^写@ 0
A good way to illustrate this concept is with an array of length `5`:
这里的读写都在`0` 。现在队列获得3个新记录`a` `b``c` 。我们的队列现在看起来像:
```js
[null, null, null, null, null]
^Read @ 0
^Write @ 0
```
> \[abc4,5]
> ^读@ 0
> ^写@ 3
Here the read and write are both at position `0`. Now the queue gets 3 new records `a`, `b`, and `c`. Our queue now looks like:
当读头读取时,它可以删除值或保留它们:
```js
[a, b, c, null, null]
^Read @ 0
^Write @ 3
```
> \[nullnullnull4,5]
> ^阅读@ 3
> ^写@ 3
As the read head reads, it can remove values or keep them:
一旦写入到达数组的末尾,它就会循环回到开头:
```js
[null, null, null, null, null]
^Read @ 3
^Write @ 3
```
> \[fnullnullde]
> ^阅读@ 3
> ^写@ 1
Now we write the values `d`, `e`, and `f` to the queue. Once the write reaches the end of the array it loops back to the beginning:
这种方法需要恒定的内存量,但允许处理更大尺寸的文件。说明:在此挑战中,我们将实现循环队列。循环队列应提供`enqueue``dequeue`方法,允许您读取和写入队列。类本身也应该接受一个整数,您可以使用该整数在创建队列时指定队列的大小。我们已经在代码编辑器中为您编写了此类的起始版本。将项目排入队列时,写入指针应向前推进,并在到达队列末尾时循环回到开头。同样,当您使项目出列时,读指针应向前推进。不应允许写指针移过读指针(我们的类不会让你覆盖你还没有读过的数据),并且读指针不能超过你写的数据。此外,如果成功,则`enqueue`方法应返回您入`enqueue`的项,否则返回`null` 。类似地,当你使一个项目出列时,它应该被返回,如果你不能出列,你应该返回`null`
```js
[f, null, null, d, e]
^Read @ 3
^Write @ 1
```
This approach requires a constant amount of memory but allows files of a much larger size to be processed.
# --instructions--
In this challenge we will implement a circular queue. The circular queue should provide `enqueue` and `dequeue` methods which allow you to read from and write to the queue. The class itself should also accept an integer argument which you can use to specify the size of the queue when created. We've written the starting version of this class for you in the code editor.
When you enqueue items to the queue, the write pointer should advance forward and loop back to the beginning once it reaches the end of the queue. The `enqueue` method should return the item you enqueued if it is successful; otherwise it will return `null`.
Likewise, the read pointer should advance forward as you dequeue items. When you dequeue an item, that item should be returned. If you cannot dequeue an item, you should return `null`.
The write pointer should not be allowed to move past the read pointer (our class won't let you overwrite data you haven't read yet) and the read pointer should not be able to advance past data you have written.
# --hints--
`enqueue`方法将项添加到循环队列。
The `enqueue` method should add items to the circular queue.
```js
assert(
@ -51,7 +71,7 @@ assert(
);
```
您不能通过读指针将项排入队列。
You should not enqueue items past the read pointer.
```js
assert(
@ -69,7 +89,7 @@ assert(
);
```
`dequeue`方法使队列中的项目出列。
The `dequeue` method should dequeue items from the queue.
```js
assert(
@ -85,7 +105,7 @@ assert(
);
```
项目出列后,其队列中的位置应重置为`null`
After an item is dequeued, its position in the queue should be reset to `null`.
```js
assert(
@ -102,7 +122,7 @@ assert(
);
```
尝试通过写指针出列队列返回`null`并且不会使写指针前进。
Trying to dequeue past the write pointer should return `null` and does not advance the write pointer.
```js
assert(