chore(learn): Applied MDX format to Chinese curriculum files (#40462)

This commit is contained in:
Randell Dawson
2020-12-16 00:37:30 -07:00
committed by GitHub
parent 873fce02a2
commit 9ce4a02a41
1665 changed files with 58741 additions and 88042 deletions

View File

@ -1,74 +1,120 @@
---
id: 587d8250367417b2b2512c60
title: 创建队列类
challengeType: 1
videoUrl: ''
title: 创建队列类
---
## Description
<section id="description">与堆栈一样队列是元素的集合。但与堆栈不同队列遵循FIFO先入先出原则。添加到队列的元素将被推送到队列的尾部或末尾并且只允许删除队列前面的元素。我们可以使用数组来表示队列但就像堆栈一样我们希望限制我们对队列的控制量。队列类的两个主要方法是enqueue和dequeue方法。 enqueue方法将元素推送到队列的尾部dequeue方法移除并返回队列前面的元素。其他有用的方法是frontsize和isEmpty方法。说明编写一个将元素推送到队列尾部的入队方法一个删除并返回前面元素的出列方法一个让我们看到前面元素的前方法一个显示长度的大小方法以及一个isEmpty方法检查队列是否为空。 </section>
# --description--
## Instructions
<section id="instructions">
</section>
与堆栈一样队列是元素的集合。但与堆栈不同队列遵循FIFO先入先出原则。添加到队列的元素将被推送到队列的尾部或末尾并且只允许删除队列前面的元素。我们可以使用数组来表示队列但就像堆栈一样我们希望限制我们对队列的控制量。队列类的两个主要方法是enqueue和dequeue方法。 enqueue方法将元素推送到队列的尾部dequeue方法移除并返回队列前面的元素。其他有用的方法是frontsize和isEmpty方法。说明编写一个将元素推送到队列尾部的入队方法一个删除并返回前面元素的出列方法一个让我们看到前面元素的前方法一个显示长度的大小方法以及一个isEmpty方法检查队列是否为空。
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: 您的<code>Queue</code>类应该有一个<code>enqueue</code>方法。
testString: assert((function(){var test = new Queue(); return (typeof test.enqueue === 'function')}()));
- text: 您的<code>Queue</code>类应该有一个<code>dequeue</code>方法。
testString: assert((function(){var test = new Queue(); return (typeof test.dequeue === 'function')}()));
- text: 您的<code>Queue</code>类应该有一个<code>front</code>方法。
testString: assert((function(){var test = new Queue(); return (typeof test.front === 'function')}()));
- text: 您的<code>Queue</code>类应该有一个<code>size</code>方法。
testString: assert((function(){var test = new Queue(); return (typeof test.size === 'function')}()));
- text: 您的<code>Queue</code>类应该有一个<code>isEmpty</code>方法。
testString: assert((function(){var test = new Queue(); return (typeof test.isEmpty === 'function')}()));
- text: <code>dequeue</code>方法应该删除并返回队列的前端元素
testString: assert((function(){var test = new Queue(); test.enqueue('Smith'); test.enqueue('John'); return (test.dequeue() === 'Smith')}()));
- text: <code>front</code>方法应该返回队列的front元素的值
testString: assert((function(){var test = new Queue(); test.enqueue('Smith'); test.enqueue('John'); return (test.front() === 'Smith')}()));
- text: <code>size</code>方法应该返回队列的长度
testString: assert((function(){var test = new Queue(); test.enqueue('Smith'); return (test.size() === 1)}()));
- text: 如果队列中有元素,则<code>isEmpty</code>方法应返回<code>false</code>
testString: assert((function(){var test = new Queue(); test.enqueue('Smith'); return !(test.isEmpty())}()));
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
您的`Queue`类应该有一个`enqueue`方法。
```js
function Queue () {
var collection = [];
this.print = function() {
console.log(collection);
};
// Only change code below this line
// Only change code above this line
}
assert(
(function () {
var test = new Queue();
return typeof test.enqueue === 'function';
})()
);
```
</div>
</section>
## Solution
<section id='solution'>
您的`Queue`类应该有一个`dequeue`方法。
```js
// solution required
assert(
(function () {
var test = new Queue();
return typeof test.dequeue === 'function';
})()
);
```
/section>
您的`Queue`类应该有一个`front`方法。
```js
assert(
(function () {
var test = new Queue();
return typeof test.front === 'function';
})()
);
```
您的`Queue`类应该有一个`size`方法。
```js
assert(
(function () {
var test = new Queue();
return typeof test.size === 'function';
})()
);
```
您的`Queue`类应该有一个`isEmpty`方法。
```js
assert(
(function () {
var test = new Queue();
return typeof test.isEmpty === 'function';
})()
);
```
`dequeue`方法应该删除并返回队列的前端元素
```js
assert(
(function () {
var test = new Queue();
test.enqueue('Smith');
test.enqueue('John');
return test.dequeue() === 'Smith';
})()
);
```
`front`方法应该返回队列的front元素的值
```js
assert(
(function () {
var test = new Queue();
test.enqueue('Smith');
test.enqueue('John');
return test.front() === 'Smith';
})()
);
```
`size`方法应该返回队列的长度
```js
assert(
(function () {
var test = new Queue();
test.enqueue('Smith');
return test.size() === 1;
})()
);
```
如果队列中有元素,则`isEmpty`方法应返回`false`
```js
assert(
(function () {
var test = new Queue();
test.enqueue('Smith');
return !test.isEmpty();
})()
);
```
# --solutions--