fix(guide) Replace invalid prism code block names (#35961)
* fix: replace sh with shell fix replace terminal with shell fix replace node with js fix replace output with shell fix replace cs with csharp fix replace c++ with cpp fix replace c# with csharp fix replace javasctipt with js fix replace syntax with js fix replace unix with shell fix replace linux with shell fix replace java 8 with java fix replace swift4 with swift fix replace react.js with jsx fix replace javascriot with js fix replace javacsript with js fix replace c++ - with cpp fix: corrected various typos fix: replace Algorithm with nothing fix: replace xaml with xml fix: replace solidity with nothing fix: replace c++ with cpp fix: replace txt with shell fix: replace code with json and css fix: replace console with shell
This commit is contained in:
committed by
Oliver Eyton-Williams
parent
4b4762716c
commit
0a1eeea424
@ -27,7 +27,7 @@ localeTitle: 洪水填充算法
|
|||||||
|
|
||||||
有关更多详细信息,请参阅此处描述该函数的代码:
|
有关更多详细信息,请参阅此处描述该函数的代码:
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
int wall = -1;
|
int wall = -1;
|
||||||
|
|
||||||
void flood_fill(int pos_x, int pos_y, int target_color, int color)
|
void flood_fill(int pos_x, int pos_y, int target_color, int color)
|
||||||
@ -80,7 +80,7 @@ int wall = -1;
|
|||||||
|
|
||||||
您有以下输入:
|
您有以下输入:
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
2 4 4
|
2 4 4
|
||||||
0 0 0 1
|
0 0 0 1
|
||||||
0 0 1 1
|
0 0 1 1
|
||||||
|
@ -21,7 +21,7 @@ C ++已经在`<queue>`库中实现了`<queue>` ,但如果您正在使用其他
|
|||||||
|
|
||||||
C ++代码:
|
C ++代码:
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
int dl[] = {-1, 0, 1, 0}; // these arrays will help you travel in the 4 directions more easily
|
int dl[] = {-1, 0, 1, 0}; // these arrays will help you travel in the 4 directions more easily
|
||||||
int dc[] = {0, 1, 0, -1};
|
int dc[] = {0, 1, 0, -1};
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ int binarySearch(int a[], int l, int r, int x) {
|
|||||||
|
|
||||||
### C / C ++实现
|
### C / C ++实现
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
int binary_search(int arr[], int l, int r, int target)
|
int binary_search(int arr[], int l, int r, int target)
|
||||||
{
|
{
|
||||||
if (r >= l)
|
if (r >= l)
|
||||||
@ -208,7 +208,7 @@ def binary_search(arr, l, r, target):
|
|||||||
|
|
||||||
### C ++中的示例
|
### C ++中的示例
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
// Binary Search using iteration
|
// Binary Search using iteration
|
||||||
int binary_search(int arr[], int beg, int end, int num)
|
int binary_search(int arr[], int beg, int end, int num)
|
||||||
{
|
{
|
||||||
@ -225,7 +225,7 @@ def binary_search(arr, l, r, target):
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
// Binary Search using recursion
|
// Binary Search using recursion
|
||||||
int binary_search(int arr[], int beg, int end, int num)
|
int binary_search(int arr[], int beg, int end, int num)
|
||||||
{
|
{
|
||||||
|
@ -75,7 +75,7 @@ def linear_search(target, array)
|
|||||||
|
|
||||||
### C ++中的示例
|
### C ++中的示例
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
int linear_search(int arr[],int n,int num)
|
int linear_search(int arr[],int n,int num)
|
||||||
{
|
{
|
||||||
for(int i=0;i<n;i++){
|
for(int i=0;i<n;i++){
|
||||||
|
@ -123,7 +123,7 @@ public class bubble-sort {
|
|||||||
|
|
||||||
### 冒泡排序的递归实现。
|
### 冒泡排序的递归实现。
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
void bubblesort(int arr[], int n)
|
void bubblesort(int arr[], int n)
|
||||||
{
|
{
|
||||||
if(n==1) //Initial Case
|
if(n==1) //Initial Case
|
||||||
|
@ -67,7 +67,7 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
在C ++中实现
|
在C ++中实现
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
void heapify(int arr[], int n, int i)
|
void heapify(int arr[], int n, int i)
|
||||||
|
@ -92,7 +92,7 @@ localeTitle: 插入排序
|
|||||||
|
|
||||||
以下算法是略微优化的版本,以避免在每次迭代中交换`key`元素。这里, `key`元素将在迭代结束时交换(步骤)。
|
以下算法是略微优化的版本,以避免在每次迭代中交换`key`元素。这里, `key`元素将在迭代结束时交换(步骤)。
|
||||||
|
|
||||||
```Algorithm
|
```
|
||||||
InsertionSort(arr[])
|
InsertionSort(arr[])
|
||||||
for j = 1 to arr.length
|
for j = 1 to arr.length
|
||||||
key = arr[j]
|
key = arr[j]
|
||||||
|
@ -23,7 +23,7 @@ T(n) = 2T(n/2) + n
|
|||||||
|
|
||||||
计算结尾总和中n的重复次数,我们看到它们有lg n + 1。因此运行时间是n(lg n + 1)= n lg n + n。我们观察到,对于n> 0,n lg n + n <n lg n + n lg n = 2n lg n,因此运行时间为O(n lg n)。
|
计算结尾总和中n的重复次数,我们看到它们有lg n + 1。因此运行时间是n(lg n + 1)= n lg n + n。我们观察到,对于n> 0,n lg n + n <n lg n + n lg n = 2n lg n,因此运行时间为O(n lg n)。
|
||||||
|
|
||||||
```Algorithm
|
```
|
||||||
MergeSort(arr[], left, right):
|
MergeSort(arr[], left, right):
|
||||||
If right > l:
|
If right > l:
|
||||||
1. Find the middle point to divide the array into two halves:
|
1. Find the middle point to divide the array into two halves:
|
||||||
|
@ -132,7 +132,8 @@ double result = 23.0 / 2;
|
|||||||
|
|
||||||
C提供了一个数学库( `math.h` ),它提供了许多有用的数学函数。例如,数字的幂可以计算为:
|
C提供了一个数学库( `math.h` ),它提供了许多有用的数学函数。例如,数字的幂可以计算为:
|
||||||
|
|
||||||
```#include<math.h>
|
```c
|
||||||
|
#include<math.h>
|
||||||
int result = pow(2,3) // will result in 2*2*2 or 8
|
int result = pow(2,3) // will result in 2*2*2 or 8
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ localeTitle: 使用body-parser来解析POST请求
|
|||||||
|
|
||||||
如果您使用提供的样板,则应该已经将身体解析器添加到您的项目中,但如果不是,它应该在那里:
|
如果您使用提供的样板,则应该已经将身体解析器添加到您的项目中,但如果不是,它应该在那里:
|
||||||
|
|
||||||
```code
|
```json
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"body-parser": "^1.4.3",
|
"body-parser": "^1.4.3",
|
||||||
...
|
...
|
||||||
|
@ -58,7 +58,7 @@ class GateKeeper extends React.Component {
|
|||||||
|
|
||||||
编写根据您的状态计算的条件语句,如质询描述中所述,检查输入的长度并将新对象分配给inputStyle变量。
|
编写根据您的状态计算的条件语句,如质询描述中所述,检查输入的长度并将新对象分配给inputStyle变量。
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
if (this.state.input.length > 15) {
|
if (this.state.input.length > 15) {
|
||||||
inputStyle = {
|
inputStyle = {
|
||||||
border: '3px solid red'
|
border: '3px solid red'
|
||||||
|
@ -10,13 +10,13 @@ localeTitle: 创建受控表格
|
|||||||
|
|
||||||
### 解
|
### 解
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
<input value={this.state.input} onChange={this.handleChange}/>
|
<input value={this.state.input} onChange={this.handleChange}/>
|
||||||
```
|
```
|
||||||
|
|
||||||
接下来,为组件创建handleSubmit方法。首先,因为您的表单正在提交,您必须阻止页面刷新。其次,调用`setState()`方法,传入要更改的不同键值对的对象。在这种情况下,您希望将“submit”设置为变量“input”的值,并将“input”设置为空字符串。
|
接下来,为组件创建handleSubmit方法。首先,因为您的表单正在提交,您必须阻止页面刷新。其次,调用`setState()`方法,传入要更改的不同键值对的对象。在这种情况下,您希望将“submit”设置为变量“input”的值,并将“input”设置为空字符串。
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
handleSubmit(event) {
|
handleSubmit(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -12,7 +12,7 @@ localeTitle: 为兄弟元素提供唯一的键属性
|
|||||||
|
|
||||||
只需将`key`属性添加到`<li>`标记即可使其唯一
|
只需将`key`属性添加到`<li>`标记即可使其唯一
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
const renderFrameworks = frontEndFrameworks.map((item) =>
|
const renderFrameworks = frontEndFrameworks.map((item) =>
|
||||||
<li key={item+1}>{item}</li>
|
<li key={item+1}>{item}</li>
|
||||||
);
|
);
|
||||||
|
@ -10,7 +10,7 @@ localeTitle: 介绍内联样式
|
|||||||
|
|
||||||
让我们逐步了解这些步骤,以便您了解其中的差异。 首先将样式标记设置为**JavaScript对象** 。
|
让我们逐步了解这些步骤,以便您了解其中的差异。 首先将样式标记设置为**JavaScript对象** 。
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
class Colorful extends React.Component {
|
class Colorful extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -26,7 +26,7 @@ class Colorful extends React.Component {
|
|||||||
|
|
||||||
其次,让我们将颜色设置为红色。
|
其次,让我们将颜色设置为红色。
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
class Colorful extends React.Component {
|
class Colorful extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -42,7 +42,7 @@ class Colorful extends React.Component {
|
|||||||
|
|
||||||
### 扰流板
|
### 扰流板
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
class Colorful extends React.Component {
|
class Colorful extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
@ -6,7 +6,7 @@ localeTitle: 覆盖默认道具
|
|||||||
|
|
||||||
此挑战使您可以覆盖Items组件的props `quantity`的默认值。其中, `quantity`默认值设置为`0` 。
|
此挑战使您可以覆盖Items组件的props `quantity`的默认值。其中, `quantity`默认值设置为`0` 。
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
const Items = (props) => {
|
const Items = (props) => {
|
||||||
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
|
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
|
||||||
}
|
}
|
||||||
@ -18,13 +18,13 @@ const Items = (props) => {
|
|||||||
|
|
||||||
要覆盖默认的props值,要遵循的语法是
|
要覆盖默认的props值,要遵循的语法是
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
<Component propsName={Value}/>
|
<Component propsName={Value}/>
|
||||||
```
|
```
|
||||||
|
|
||||||
在语法之后,应在给定代码下面声明以下代码
|
在语法之后,应在给定代码下面声明以下代码
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
<Items quantity={50}/>
|
<Items quantity={50}/>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ localeTitle: 从道具有条理地渲染
|
|||||||
|
|
||||||
使用适当的增量声明更改`handleClick()` 。
|
使用适当的增量声明更改`handleClick()` 。
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
handleClick() {
|
handleClick() {
|
||||||
this.setState({
|
this.setState({
|
||||||
counter: this.state.counter + 1
|
counter: this.state.counter + 1
|
||||||
@ -20,7 +20,7 @@ handleClick() {
|
|||||||
|
|
||||||
在`render()`方法中,使用质询描述中提到的`Math.random()`并编写三元表达式以在**Results**组件中传递`props` 。
|
在`render()`方法中,使用质询描述中提到的`Math.random()`并编写三元表达式以在**Results**组件中传递`props` 。
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
let expression = Math.random() > .5;
|
let expression = Math.random() > .5;
|
||||||
|
|
||||||
{(expression == 1)? <Results fiftyFifty="You win!"/> : <Results fiftyFifty="You lose!"/> }
|
{(expression == 1)? <Results fiftyFifty="You win!"/> : <Results fiftyFifty="You lose!"/> }
|
||||||
@ -28,7 +28,7 @@ handleClick() {
|
|||||||
|
|
||||||
然后在Results组件中渲染`fiftyFifty`道具。
|
然后在Results组件中渲染`fiftyFifty`道具。
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
<h1>
|
<h1>
|
||||||
{
|
{
|
||||||
this.props.fiftyFifty
|
this.props.fiftyFifty
|
||||||
|
@ -12,7 +12,7 @@ localeTitle: 在用户界面中渲染状态
|
|||||||
|
|
||||||
## 解
|
## 解
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
class MyComponent extends React.Component {
|
class MyComponent extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -12,7 +12,7 @@ localeTitle: 使用If / Else条件渲染
|
|||||||
|
|
||||||
### 解
|
### 解
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
if (this.state.display === true) {
|
if (this.state.display === true) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -25,7 +25,7 @@ if (this.state.display === true) {
|
|||||||
|
|
||||||
接下来,创建一个else语句,返回**不带** `h1`元素的相同JSX。
|
接下来,创建一个else语句,返回**不带** `h1`元素的相同JSX。
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
else {
|
else {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -17,7 +17,7 @@ condition ? expressionIfTrue : expressionIfFalse
|
|||||||
|
|
||||||
这是使用三元表达的示例解决方案。 首先,您需要在构造函数中声明状态,如下所示
|
这是使用三元表达的示例解决方案。 首先,您需要在构造函数中声明状态,如下所示
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
// change code below this line
|
// change code below this line
|
||||||
@ -33,7 +33,7 @@ constructor(props) {
|
|||||||
|
|
||||||
然后是三元运算符
|
然后是三元运算符
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
{
|
{
|
||||||
/* change code here */
|
/* change code here */
|
||||||
(this.state.userAge >= 18) ? buttonTwo : (this.state.userAge== '')? buttonOne: buttonThree
|
(this.state.userAge >= 18) ? buttonTwo : (this.state.userAge== '')? buttonOne: buttonThree
|
||||||
|
@ -6,7 +6,7 @@ localeTitle: 使用PropTypes定义您期望的道具
|
|||||||
|
|
||||||
您可以通过此挑战为`Items`组件设置`propTypes` 。
|
您可以通过此挑战为`Items`组件设置`propTypes` 。
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
const Items = (props) => {
|
const Items = (props) => {
|
||||||
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
|
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
|
||||||
};
|
};
|
||||||
@ -14,7 +14,7 @@ const Items = (props) => {
|
|||||||
|
|
||||||
要设置propTypes,要遵循的语法是
|
要设置propTypes,要遵循的语法是
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
itemName.propTypes = {
|
itemName.propTypes = {
|
||||||
props: PropTypes.dataType.isRequired
|
props: PropTypes.dataType.isRequired
|
||||||
};
|
};
|
||||||
@ -22,7 +22,7 @@ itemName.propTypes = {
|
|||||||
|
|
||||||
在语法之后,应该在`Items`组件的`quantity`道具的给定代码下面设置以下代码
|
在语法之后,应该在`Items`组件的`quantity`道具的给定代码下面设置以下代码
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
Items.propTypes = {
|
Items.propTypes = {
|
||||||
quantity: PropTypes.number.isRequired
|
quantity: PropTypes.number.isRequired
|
||||||
};
|
};
|
||||||
|
@ -6,9 +6,9 @@ localeTitle: 定义Redux动作
|
|||||||
|
|
||||||
以下是如何声明Redux Action。
|
以下是如何声明Redux Action。
|
||||||
|
|
||||||
```react.js
|
```js
|
||||||
let action={
|
let action={
|
||||||
type: 'LOGIN'
|
type: 'LOGIN'
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -6,7 +6,7 @@ localeTitle: 派遣行动事件
|
|||||||
|
|
||||||
通过调用dispatch方法将LOGIN操作发送到Redux存储,并传入`loginAction()`创建的操作。
|
通过调用dispatch方法将LOGIN操作发送到Redux存储,并传入`loginAction()`创建的操作。
|
||||||
|
|
||||||
```react.js
|
```js
|
||||||
store.dispatch(loginAction());
|
store.dispatch(loginAction());
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -6,7 +6,7 @@ localeTitle: 从Redux商店获取状态
|
|||||||
|
|
||||||
使用`getState()`方法从存储中检索数据。
|
使用`getState()`方法从存储中检索数据。
|
||||||
|
|
||||||
```react.js
|
```js
|
||||||
let currentState = store.getState();
|
let currentState = store.getState();
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@ -14,7 +14,7 @@ localeTitle: 匹配具有不同可能性的文字字符串
|
|||||||
|
|
||||||
## 解:
|
## 解:
|
||||||
|
|
||||||
```javascriot
|
```js
|
||||||
let petString = "James has a pet cat.";
|
let petString = "James has a pet cat.";
|
||||||
let petRegex = /dog|cat|bird|fish/;
|
let petRegex = /dog|cat|bird|fish/;
|
||||||
let result = petRegex.test(petString);
|
let result = petRegex.test(petString);
|
||||||
|
@ -24,7 +24,7 @@ let exampleRegExp = /[^az]/;
|
|||||||
|
|
||||||
一定要检查你的号码范围是否正确 - 挑战要求我们否定0-99之间的所有数字。这可以使用在正则表达式的第一个开始括号后立即放置的否定插入符来完成。
|
一定要检查你的号码范围是否正确 - 挑战要求我们否定0-99之间的所有数字。这可以使用在正则表达式的第一个开始括号后立即放置的否定插入符来完成。
|
||||||
|
|
||||||
```javacsript
|
```js
|
||||||
let numbersRegExp = /[^0-99]/ig;
|
let numbersRegExp = /[^0-99]/ig;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ localeTitle: 堆栈
|
|||||||
|
|
||||||
使用数组或链表可以实现堆栈。以下是具有最常见操作的堆栈数据结构的简单数组实现。
|
使用数组或链表可以实现堆栈。以下是具有最常见操作的堆栈数据结构的简单数组实现。
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
//Stack implementation using array in C++
|
//Stack implementation using array in C++
|
||||||
//You can also include<stack> and then use the C++ STL Library stack class.
|
//You can also include<stack> and then use the C++ STL Library stack class.
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
|
|||||||
|
|
||||||
创建并启动容器
|
创建并启动容器
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
$ docker create -t -i fedora bash
|
$ docker create -t -i fedora bash
|
||||||
|
|
||||||
```
|
```
|
@ -8,13 +8,13 @@ localeTitle: C ++数组
|
|||||||
|
|
||||||
例如,包含5个称为数字的整数值的数组声明如下:
|
例如,包含5个称为数字的整数值的数组声明如下:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
int numbers [5];
|
int numbers [5];
|
||||||
```
|
```
|
||||||
|
|
||||||
Initializiation:
|
Initializiation:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
//Initialization with entries:
|
//Initialization with entries:
|
||||||
int numbers [5] = {1, 2, 3, 4, 5};
|
int numbers [5] = {1, 2, 3, 4, 5};
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ Initializiation:
|
|||||||
可以通过引用它们在数组中的位置来访问数组中的元素。 (从0开始计数)。
|
可以通过引用它们在数组中的位置来访问数组中的元素。 (从0开始计数)。
|
||||||
例:
|
例:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
x = numbers[0]; // = 1. [0] == first position
|
x = numbers[0]; // = 1. [0] == first position
|
||||||
numbers[2] = 55; // Sets the third position (3) to the new number 55
|
numbers[2] = 55; // Sets the third position (3) to the new number 55
|
||||||
//numbers[] is now: {1, 2, 55, 4, 5}
|
//numbers[] is now: {1, 2, 55, 4, 5}
|
||||||
|
@ -37,7 +37,7 @@ update语句用于通过使用加法,减法,乘法或除法等简单操作
|
|||||||
|
|
||||||
## 实现:
|
## 实现:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std; // Here we use the scope resolution operator to define the scope of the standar functions as std::
|
using namespace std; // Here we use the scope resolution operator to define the scope of the standar functions as std::
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ localeTitle: 输入和输出
|
|||||||
|
|
||||||
“Hello World”程序使用`cout`打印“Hello World!”到控制台:
|
“Hello World”程序使用`cout`打印“Hello World!”到控制台:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -30,24 +30,24 @@ localeTitle: 输入和输出
|
|||||||
|
|
||||||
几乎所有东西都可以放入一个流:字符串,数字,变量,表达式等。这里有一些有效的流插入示例:
|
几乎所有东西都可以放入一个流:字符串,数字,变量,表达式等。这里有一些有效的流插入示例:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
// Notice we can use the number 42 and not the string "42".
|
// Notice we can use the number 42 and not the string "42".
|
||||||
cout << "The meaning of life is " << 42 << endl;` // Output: The meaning of life is 42
|
cout << "The meaning of life is " << 42 << endl;` // Output: The meaning of life is 42
|
||||||
```
|
```
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
string name = "Tim";
|
string name = "Tim";
|
||||||
cout << "Except for you, " << name << endl;`// Output: Except for you, Tim
|
cout << "Except for you, " << name << endl;`// Output: Except for you, Tim
|
||||||
```
|
```
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
string name = "Tim";
|
string name = "Tim";
|
||||||
cout << name;
|
cout << name;
|
||||||
cout << " is a great guy!" << endl;`
|
cout << " is a great guy!" << endl;`
|
||||||
// Output: Tim is a great guy!
|
// Output: Tim is a great guy!
|
||||||
```
|
```
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
int a = 3;
|
int a = 3;
|
||||||
cout << a*2 + 18/a << endl;`// Output: 12
|
cout << a*2 + 18/a << endl;`// Output: 12
|
||||||
```
|
```
|
||||||
@ -56,7 +56,7 @@ int a = 3;
|
|||||||
|
|
||||||
C ++总是让_你_掌控,并且只完成你告诉它要做的事情。这有时会令人惊讶,如下例所示:
|
C ++总是让_你_掌控,并且只完成你告诉它要做的事情。这有时会令人惊讶,如下例所示:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
string name = "Sarah";
|
string name = "Sarah";
|
||||||
cout << "Good morning" << name << "how are you today? << endl;
|
cout << "Good morning" << name << "how are you today? << endl;
|
||||||
```
|
```
|
||||||
@ -65,7 +65,7 @@ string name = "Sarah";
|
|||||||
|
|
||||||
换行也不会自己发生。你可能会认为这会在四行打印一个食谱:
|
换行也不会自己发生。你可能会认为这会在四行打印一个食谱:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
cout << "To make bread, you need:";
|
cout << "To make bread, you need:";
|
||||||
cout << "* One egg";
|
cout << "* One egg";
|
||||||
cout << "* One water";
|
cout << "* One water";
|
||||||
@ -76,7 +76,7 @@ cout << "To make bread, you need:";
|
|||||||
|
|
||||||
您可以通过在每行之后添加`endl`来解决此问题,因为如前所述, `endl`在换行流中插入换行符。但是,它也会强制冲洗缓冲区,这会让我们失去一点性能,因为我们可以一次打印所有的线条。因此,最好的方法是在行尾添加实际的换行符,并且最后只使用`endl` :
|
您可以通过在每行之后添加`endl`来解决此问题,因为如前所述, `endl`在换行流中插入换行符。但是,它也会强制冲洗缓冲区,这会让我们失去一点性能,因为我们可以一次打印所有的线条。因此,最好的方法是在行尾添加实际的换行符,并且最后只使用`endl` :
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
cout << "To make bread, you need:\n";
|
cout << "To make bread, you need:\n";
|
||||||
cout << "* One egg\n";
|
cout << "* One egg\n";
|
||||||
cout << "* One water\n";
|
cout << "* One water\n";
|
||||||
@ -89,7 +89,7 @@ cout << "To make bread, you need:\n";
|
|||||||
|
|
||||||
要从控制台中读取,您可以像使用`cout`一样使用_输入流_ `cin` ,但不要将内容放入`cin` ,而是“将它们取出”。以下程序从用户读取两个数字并将它们加在一起:
|
要从控制台中读取,您可以像使用`cout`一样使用_输入流_ `cin` ,但不要将内容放入`cin` ,而是“将它们取出”。以下程序从用户读取两个数字并将它们加在一起:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ cout << "To make bread, you need:\n";
|
|||||||
|
|
||||||
提取运算符`<<`也可以链接。这是与上次相同的程序,但是以更简洁的方式编写:
|
提取运算符`<<`也可以链接。这是与上次相同的程序,但是以更简洁的方式编写:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ localeTitle: 地图
|
|||||||
|
|
||||||
这是一个例子:
|
这是一个例子:
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ a => 10
|
|||||||
|
|
||||||
使用插入成员函数插入数据。
|
使用插入成员函数插入数据。
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
myMap.insert(make_pair("earth", 1));
|
myMap.insert(make_pair("earth", 1));
|
||||||
myMap.insert(make_pair("moon", 2));
|
myMap.insert(make_pair("moon", 2));
|
||||||
```
|
```
|
||||||
@ -69,7 +69,7 @@ myMap.insert(make_pair("earth", 1));
|
|||||||
|
|
||||||
要访问地图元素,您必须为它创建迭代器。这是前面提到的一个例子。
|
要访问地图元素,您必须为它创建迭代器。这是前面提到的一个例子。
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
map<char, int>::iterator it;
|
map<char, int>::iterator it;
|
||||||
for(it=first.begin(); it!=first.end(); ++it){
|
for(it=first.begin(); it!=first.end(); ++it){
|
||||||
cout << it->first << " => " << it->second << '\n';
|
cout << it->first << " => " << it->second << '\n';
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
---
|
---
|
||||||
title: IDE and Printing different text
|
title: IDE and Printing different text
|
||||||
localeTitle: IDE和打印不同的文本
|
localeTitle: IDE和打印不同的文本
|
||||||
---
|
---
|
||||||
|
# IDE简介和打印不同的文本:
|
||||||
|
|
||||||
* 在上一篇文章中,有一些编程所需软件的下载链接。像这样的软件被称为IDE。 **IDE代表集成开发环境**
|
* 在上一篇文章中,有一些编程所需软件的下载链接。像这样的软件被称为IDE。 **IDE代表集成开发环境**
|
||||||
|
|
||||||
@ -33,8 +34,7 @@ _问:尝试在Google上搜索IDE并在其上运行您的第一个程序。检
|
|||||||
```
|
```
|
||||||
|
|
||||||
上面的代码返回一个错误,因为在第2行,我们使用了冒号(:)而不是分号(;) 那么,让我们调试错误:
|
上面的代码返回一个错误,因为在第2行,我们使用了冒号(:)而不是分号(;) 那么,让我们调试错误:
|
||||||
上面的代码返回一个错误,因为在第2行,我们使用了冒号(:)而不是分号(;) 那么,让我们调试错误:
|
```cpp
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std ;
|
using namespace std ;
|
||||||
int main()
|
int main()
|
||||||
@ -139,4 +139,4 @@ Hello World! I love freeCodeCamp!
|
|||||||
|
|
||||||
`cpp (7!=5);` 评估结果为true
|
`cpp (7!=5);` 评估结果为true
|
||||||
|
|
||||||
|
[本文中使用的所有打印语句的总和。随意调整代码! :)](https://repl.it/L4ox)
|
||||||
|
@ -10,7 +10,7 @@ while循环的一个关键点是循环可能永远不会运行。 当测试条
|
|||||||
|
|
||||||
例:
|
例:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ localeTitle: 对于循环
|
|||||||
|
|
||||||
## 句法
|
## 句法
|
||||||
|
|
||||||
```C#
|
```csharp
|
||||||
for ((Initial variable); (condition); (step))
|
for ((Initial variable); (condition); (step))
|
||||||
{
|
{
|
||||||
(code)
|
(code)
|
||||||
@ -25,7 +25,7 @@ C#for循环由三个表达式和一些代码组成。
|
|||||||
|
|
||||||
## 例
|
## 例
|
||||||
|
|
||||||
```C#
|
```csharp
|
||||||
int[] array = { 1, 2, 3, 4, 5 };
|
int[] array = { 1, 2, 3, 4, 5 };
|
||||||
for (int i = 0; i < array.Length; i++)
|
for (int i = 0; i < array.Length; i++)
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,7 @@ foreach (element in iterable-item)
|
|||||||
|
|
||||||
### 输出:
|
### 输出:
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
> We have Jim
|
> We have Jim
|
||||||
> We have Jane
|
> We have Jane
|
||||||
> We have Jack
|
> We have Jack
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
---
|
---
|
||||||
title: Hello World
|
title: Hello World
|
||||||
localeTitle: 你好,世界
|
localeTitle: 你好,世界
|
||||||
---
|
---
|
||||||
|
# 你好,世界
|
||||||
|
|
||||||
要在控制台上编写一些文本,我们使用`Console.WriteLine()` 。此方法将字符串作为输入。
|
要在控制台上编写一些文本,我们使用`Console.WriteLine()` 。此方法将字符串作为输入。
|
||||||
|
|
||||||
@ -28,9 +29,8 @@ using System;
|
|||||||
```
|
```
|
||||||
|
|
||||||
## 输出:
|
## 输出:
|
||||||
## 输出:
|
```shell
|
||||||
|
|
||||||
> Hello World!
|
> Hello World!
|
||||||
> Press any key to exit.
|
> Press any key to exit.
|
||||||
|
|
||||||
|
```
|
||||||
|
@ -10,7 +10,7 @@ C#中的null-coalescing运算符用于帮助将一个变量分配给另一个
|
|||||||
|
|
||||||
由于`name`为`null` , `clientName`将为`clientName`分配值“John Doe”。
|
由于`name`为`null` , `clientName`将为`clientName`分配值“John Doe”。
|
||||||
|
|
||||||
```cs
|
```csharp
|
||||||
string name = null;
|
string name = null;
|
||||||
|
|
||||||
string clientName = name ?? "John Doe";
|
string clientName = name ?? "John Doe";
|
||||||
@ -18,7 +18,7 @@ string name = null;
|
|||||||
Console.WriteLine(clientName);
|
Console.WriteLine(clientName);
|
||||||
```
|
```
|
||||||
|
|
||||||
```cs
|
```csharp
|
||||||
> John Doe
|
> John Doe
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ string name = null;
|
|||||||
|
|
||||||
由于`name`不为`null` , `clientName`将为`clientName`分配`name`的值,即“Jane Smith”。
|
由于`name`不为`null` , `clientName`将为`clientName`分配`name`的值,即“Jane Smith”。
|
||||||
|
|
||||||
```cs
|
```csharp
|
||||||
string name = "Jane Smith";
|
string name = "Jane Smith";
|
||||||
|
|
||||||
string clientName = name ?? "John Doe";
|
string clientName = name ?? "John Doe";
|
||||||
@ -34,7 +34,7 @@ string name = "Jane Smith";
|
|||||||
Console.WriteLine(clientName);
|
Console.WriteLine(clientName);
|
||||||
```
|
```
|
||||||
|
|
||||||
```cs
|
```csharp
|
||||||
> Jane Smith
|
> Jane Smith
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ string name = "Jane Smith";
|
|||||||
|
|
||||||
您可以使用`if...else`语句来测试是否存在`null`并分配不同的值。
|
您可以使用`if...else`语句来测试是否存在`null`并分配不同的值。
|
||||||
|
|
||||||
```cs
|
```csharp
|
||||||
string clientName;
|
string clientName;
|
||||||
|
|
||||||
if (name != null)
|
if (name != null)
|
||||||
@ -53,7 +53,7 @@ string clientName;
|
|||||||
|
|
||||||
但是,使用null-coalescing运算符可以大大简化这一点。
|
但是,使用null-coalescing运算符可以大大简化这一点。
|
||||||
|
|
||||||
```cs
|
```csharp
|
||||||
string clientName = name ?? "John Doe";
|
string clientName = name ?? "John Doe";
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -61,13 +61,13 @@ string clientName = name ?? "John Doe";
|
|||||||
|
|
||||||
也可以使用条件运算符来测试`null`的存在并分配不同的值。
|
也可以使用条件运算符来测试`null`的存在并分配不同的值。
|
||||||
|
|
||||||
```cs
|
```csharp
|
||||||
string clientName = name != null ? name : "John Doe";
|
string clientName = name != null ? name : "John Doe";
|
||||||
```
|
```
|
||||||
|
|
||||||
同样,这可以使用null-coalescing运算符进行简化。
|
同样,这可以使用null-coalescing运算符进行简化。
|
||||||
|
|
||||||
```cs
|
```csharp
|
||||||
string clientName = name ?? "John Doe";
|
string clientName = name ?? "John Doe";
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ Silverlight,移动开发,WPF(Windows Presentation Foindation),Windows
|
|||||||
|
|
||||||
以下示例显示了带有“Hello World!”的标签。作为其顶级容器中的内容,称为UserControl。
|
以下示例显示了带有“Hello World!”的标签。作为其顶级容器中的内容,称为UserControl。
|
||||||
|
|
||||||
```XAML
|
```xml
|
||||||
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
<Label Content="Hello World!" />
|
<Label Content="Hello World!" />
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
@ -174,7 +174,7 @@ CSS断点可以被认为是响应式网页设计的核心,因为它们定义
|
|||||||
|
|
||||||
您还可以设置最小和最大宽度,让您使用不同的范围进行实验。这个大致触发了smar-phone和更大的桌面和显示器尺寸
|
您还可以设置最小和最大宽度,让您使用不同的范围进行实验。这个大致触发了smar-phone和更大的桌面和显示器尺寸
|
||||||
|
|
||||||
```code
|
```css
|
||||||
@media only screen and (min-width: 700px) and (max-width: 1500px) {
|
@media only screen and (min-width: 700px) and (max-width: 1500px) {
|
||||||
something {
|
something {
|
||||||
something: something;
|
something: something;
|
||||||
|
@ -6,7 +6,7 @@ localeTitle: 使用pacman在Arch Linux中安装Go
|
|||||||
|
|
||||||
使用Arch Linux Package Manager(pacman)是安装Go的最简单方法。基于Arch Linux非常快速地提供新软件版本的理念,您将获得最新版本的go。 在安装go软件包之前,必须使系统保持最新状态。
|
使用Arch Linux Package Manager(pacman)是安装Go的最简单方法。基于Arch Linux非常快速地提供新软件版本的理念,您将获得最新版本的go。 在安装go软件包之前,必须使系统保持最新状态。
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
$ sudo pacman -Syu
|
$ sudo pacman -Syu
|
||||||
$ sudo pacman -S go
|
$ sudo pacman -S go
|
||||||
```
|
```
|
||||||
@ -15,7 +15,7 @@ $ sudo pacman -Syu
|
|||||||
|
|
||||||
要检查go是否已成功安装,请使用:
|
要检查go是否已成功安装,请使用:
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
$ go version
|
$ go version
|
||||||
> go version go2.11.1 linux/amd64
|
> go version go2.11.1 linux/amd64
|
||||||
```
|
```
|
||||||
|
@ -12,7 +12,7 @@ localeTitle: 使用Package Installer在Mac OS X中安装Go
|
|||||||
|
|
||||||
要检查是否已成功安装,请打开终端并使用:
|
要检查是否已成功安装,请打开终端并使用:
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
$ go version
|
$ go version
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ $ curl -O https://storage.googleapis.com/golang/go1.9.1.darwin-amd64.tar.gz
|
|||||||
|
|
||||||
要检查go是否已成功安装,请使用:
|
要检查go是否已成功安装,请使用:
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
$ go version
|
$ go version
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ localeTitle: 使用apt-get在Ubuntu中安装Go
|
|||||||
|
|
||||||
> 在撰写本文时,Ubuntu Xenial的版本是1.6.1,而最新版本 稳定版本是1.9.1
|
> 在撰写本文时,Ubuntu Xenial的版本是1.6.1,而最新版本 稳定版本是1.9.1
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
$ sudo apt-get update
|
$ sudo apt-get update
|
||||||
$ sudo apt-get install golang-go
|
$ sudo apt-get install golang-go
|
||||||
```
|
```
|
||||||
@ -17,7 +17,7 @@ $ sudo apt-get update
|
|||||||
|
|
||||||
要检查go是否已成功安装,请使用:
|
要检查go是否已成功安装,请使用:
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
$ go version
|
$ go version
|
||||||
> go version go1.9.1 linux/amd64
|
> go version go1.9.1 linux/amd64
|
||||||
```
|
```
|
||||||
|
@ -10,7 +10,7 @@ localeTitle: 使用tarball在Ubuntu中安装Go
|
|||||||
|
|
||||||
在继续之前,请确保您知道您的系统是32位还是64位。如果您不知道,请运行以下命令以查找:
|
在继续之前,请确保您知道您的系统是32位还是64位。如果您不知道,请运行以下命令以查找:
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
$ lscpu | grep Architecture
|
$ lscpu | grep Architecture
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ $ wget https://storage.googleapis.com/golang/go1.9.1.linux-386.tar.gz
|
|||||||
|
|
||||||
要检查go是否已成功安装,请使用:
|
要检查go是否已成功安装,请使用:
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
$ go version
|
$ go version
|
||||||
> go version go1.9.1 linux/amd64
|
> go version go1.9.1 linux/amd64
|
||||||
```
|
```
|
||||||
|
@ -10,7 +10,7 @@ JavaScript的`with`语句是在一个对象上编辑多个属性的简便方法
|
|||||||
|
|
||||||
### 句法
|
### 句法
|
||||||
|
|
||||||
```syntax
|
```js
|
||||||
with (expression)
|
with (expression)
|
||||||
statement
|
statement
|
||||||
```
|
```
|
||||||
|
@ -63,7 +63,7 @@ localeTitle: 基本Linux命令
|
|||||||
15. **grep** - grep搜索任何给定的输入文件,选择与一个或多个模式匹配的行。
|
15. **grep** - grep搜索任何给定的输入文件,选择与一个或多个模式匹配的行。
|
||||||
- 使用`grep`查找文件,目录,文件/目录中的一些文本。
|
- 使用`grep`查找文件,目录,文件/目录中的一些文本。
|
||||||
**例子:**
|
**例子:**
|
||||||
```sh
|
```shell
|
||||||
$ ps ax | grep -w login
|
$ ps ax | grep -w login
|
||||||
25291 s000 Ss 0:00.11 login -pf <user>
|
25291 s000 Ss 0:00.11 login -pf <user>
|
||||||
25467 s000 R+ 0:00.00 grep -w login
|
25467 s000 R+ 0:00.00 grep -w login
|
||||||
|
@ -22,7 +22,7 @@ Linux的终端不用担心,实际上它很容易使用一些练习,它可以
|
|||||||
|
|
||||||
cd(更改目录) - cd命令是您在linux命令行中使用最多的命令之一。它允许您更改工作目录。您可以使用它在文件系统的层次结构中移动。
|
cd(更改目录) - cd命令是您在linux命令行中使用最多的命令之一。它允许您更改工作目录。您可以使用它在文件系统的层次结构中移动。
|
||||||
|
|
||||||
```unix
|
```shell
|
||||||
cd
|
cd
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ cd
|
|||||||
|
|
||||||
ls(List) - 该命令列出当前目录中的内容。它还可以用于列出文件信息。
|
ls(List) - 该命令列出当前目录中的内容。它还可以用于列出文件信息。
|
||||||
|
|
||||||
```unix
|
```shell
|
||||||
ls
|
ls
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ localeTitle: 如何使用SFTP通过远程服务器安全地传输文件
|
|||||||
|
|
||||||
如果您还没有,请测试您是否能够SSH到服务器。 SFTP使用Secure Shell(SSH)协议,因此如果您无法通过SSH,您可能也无法使用SFTP。
|
如果您还没有,请测试您是否能够SSH到服务器。 SFTP使用Secure Shell(SSH)协议,因此如果您无法通过SSH,您可能也无法使用SFTP。
|
||||||
|
|
||||||
```unix
|
```shell
|
||||||
ssh your_username@hostname_or_ip_address
|
ssh your_username@hostname_or_ip_address
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -18,13 +18,13 @@ ssh your_username@hostname_or_ip_address
|
|||||||
|
|
||||||
它使用与SSH相同的语法,并打开一个可以传输文件的会话。
|
它使用与SSH相同的语法,并打开一个可以传输文件的会话。
|
||||||
|
|
||||||
```unix
|
```shell
|
||||||
sftp your_username@hostname_or_ip_address
|
sftp your_username@hostname_or_ip_address
|
||||||
```
|
```
|
||||||
|
|
||||||
要列出有用的命令:
|
要列出有用的命令:
|
||||||
|
|
||||||
```unix
|
```shell
|
||||||
help
|
help
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -32,19 +32,19 @@ help
|
|||||||
|
|
||||||
要下载文件:
|
要下载文件:
|
||||||
|
|
||||||
```unix
|
```shell
|
||||||
get <filename>
|
get <filename>
|
||||||
```
|
```
|
||||||
|
|
||||||
要下载文件夹及其内容,请使用“-r”标志(也可用于上载):
|
要下载文件夹及其内容,请使用“-r”标志(也可用于上载):
|
||||||
|
|
||||||
```unix
|
```shell
|
||||||
get -r <foldername>
|
get -r <foldername>
|
||||||
```
|
```
|
||||||
|
|
||||||
要上传文件:
|
要上传文件:
|
||||||
|
|
||||||
```unix
|
```shell
|
||||||
put <filename>
|
put <filename>
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -52,13 +52,13 @@ put <filename>
|
|||||||
|
|
||||||
要更改本地文件夹:
|
要更改本地文件夹:
|
||||||
|
|
||||||
```unix
|
```shell
|
||||||
lcd <path/to/folder>
|
lcd <path/to/folder>
|
||||||
```
|
```
|
||||||
|
|
||||||
要更改远程文件夹:
|
要更改远程文件夹:
|
||||||
|
|
||||||
```unix
|
```shell
|
||||||
cd <path/to/folder>
|
cd <path/to/folder>
|
||||||
|
|
||||||
```
|
```
|
@ -10,7 +10,7 @@ RPM包文件是Red Hat Package Manager文件,可以在Red Hat / CentOS Linux
|
|||||||
|
|
||||||
第1步:检查是否存在现有存储库。
|
第1步:检查是否存在现有存储库。
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
#yum repolist
|
#yum repolist
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -18,19 +18,19 @@ RPM包文件是Red Hat Package Manager文件,可以在Red Hat / CentOS Linux
|
|||||||
|
|
||||||
第2步:将目录更改为
|
第2步:将目录更改为
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
#cd /etc/yum.repos.d
|
#cd /etc/yum.repos.d
|
||||||
```
|
```
|
||||||
|
|
||||||
第3步:创建新文件
|
第3步:创建新文件
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
#vim myrepo.repo
|
#vim myrepo.repo
|
||||||
```
|
```
|
||||||
|
|
||||||
第4步:在文件中键入以下行
|
第4步:在文件中键入以下行
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
[file-name]
|
[file-name]
|
||||||
name=filename
|
name=filename
|
||||||
baseurl="location of yum repositories"
|
baseurl="location of yum repositories"
|
||||||
@ -41,7 +41,7 @@ RPM包文件是Red Hat Package Manager文件,可以在Red Hat / CentOS Linux
|
|||||||
|
|
||||||
第6步:重复步骤1
|
第6步:重复步骤1
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
You Will find repositories
|
You Will find repositories
|
||||||
|
|
||||||
```
|
```
|
@ -14,7 +14,7 @@ localeTitle: Linux命令行的剖析
|
|||||||
|
|
||||||
要开始使用打开终端(对于Ubuntu只需按住Ctrl + Alt + T),你会受到以这种格式排列的一系列字符的欢迎;
|
要开始使用打开终端(对于Ubuntu只需按住Ctrl + Alt + T),你会受到以这种格式排列的一系列字符的欢迎;
|
||||||
|
|
||||||
```linux
|
```shell
|
||||||
user_name@machine_name:~$
|
user_name@machine_name:~$
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ import time
|
|||||||
|
|
||||||
**Node.js的**
|
**Node.js的**
|
||||||
|
|
||||||
```node
|
```js
|
||||||
function my_io_task() {
|
function my_io_task() {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
console.log('done');
|
console.log('done');
|
||||||
|
@ -52,7 +52,7 @@ For循环通常用于计算一定数量的迭代以重复语句。
|
|||||||
|
|
||||||
这将输出:
|
这将输出:
|
||||||
|
|
||||||
```txt
|
```shell
|
||||||
int(1) int(2) int(3) NULL
|
int(1) int(2) int(3) NULL
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ localeTitle: 编码标准
|
|||||||
|
|
||||||
这是你如何检查你的python代码是否符合他的标准。
|
这是你如何检查你的python代码是否符合他的标准。
|
||||||
|
|
||||||
```console
|
```shell
|
||||||
:~$ pip install pep8
|
:~$ pip install pep8
|
||||||
:~$ pep8 --first myCode.py
|
:~$ pep8 --first myCode.py
|
||||||
```
|
```
|
||||||
|
@ -12,7 +12,7 @@ localeTitle: 使用PropTypes进行React TypeChecking
|
|||||||
|
|
||||||
为了使用它,需要通过在控制台中发出以下命令将其作为依赖项添加到项目中。
|
为了使用它,需要通过在控制台中发出以下命令将其作为依赖项添加到项目中。
|
||||||
|
|
||||||
```sh
|
```shell
|
||||||
npm install --save prop-types
|
npm install --save prop-types
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
---
|
---
|
||||||
title: React Redux Basic Setup
|
title: React Redux Basic Setup
|
||||||
localeTitle: React Redux Basic Setup
|
localeTitle: React Redux Basic Setup
|
||||||
---
|
---
|
||||||
|
## React Redux Basic Setup
|
||||||
|
|
||||||
在本指南中,将向读者介绍如何设置简单的React和Redux应用程序。
|
在本指南中,将向读者介绍如何设置简单的React和Redux应用程序。
|
||||||
|
|
||||||
@ -12,8 +13,7 @@ localeTitle: React Redux Basic Setup
|
|||||||
假设所有设置都正常并且正常工作,则需要添加一些软件包才能使Redux与React一起工作。
|
假设所有设置都正常并且正常工作,则需要添加一些软件包才能使Redux与React一起工作。
|
||||||
|
|
||||||
在已创建的项目文件夹中打开一个终端并发出以下命令
|
在已创建的项目文件夹中打开一个终端并发出以下命令
|
||||||
在已创建的项目文件夹中打开一个终端并发出以下命令
|
```shell
|
||||||
|
|
||||||
npm install --save react react react-dom react-redux react-router redux
|
npm install --save react react react-dom react-redux react-router redux
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -277,4 +277,4 @@ export defaultStoreStore( 例 ); \`\`\` 上面的代码演示了如何定义
|
|||||||
|
|
||||||
[Redux Api](http://redux.js.org/docs/api/)
|
[Redux Api](http://redux.js.org/docs/api/)
|
||||||
|
|
||||||
|
[Redux示例](https://github.com/reactjs/redux/tree/master/examples)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
---
|
---
|
||||||
title: Installing Rust
|
title: Installing Rust
|
||||||
localeTitle: 安装Rust
|
localeTitle: 安装Rust
|
||||||
---
|
---
|
||||||
|
# 安装Rust
|
||||||
|
|
||||||
使用`rustup`是Rust安装的首选。 `rustup`为您的系统安装和管理Rust。
|
使用`rustup`是Rust安装的首选。 `rustup`为您的系统安装和管理Rust。
|
||||||
|
|
||||||
@ -12,8 +13,7 @@ localeTitle: 安装Rust
|
|||||||
## 在其他操作系统中安装Rust(Mac OS X,Linux,BSD,Unix)
|
## 在其他操作系统中安装Rust(Mac OS X,Linux,BSD,Unix)
|
||||||
|
|
||||||
打开终端并输入以下命令:
|
打开终端并输入以下命令:
|
||||||
打开终端并输入以下命令:
|
```shell
|
||||||
|
|
||||||
curl https://sh.rustup.rs -sSf | sh
|
curl https://sh.rustup.rs -sSf | sh
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -22,8 +22,7 @@ curl https://sh.rustup.rs -sSf | sh
|
|||||||
# 验证安装
|
# 验证安装
|
||||||
|
|
||||||
安装`rustup`将安装与rust相关的所有内容,但最重要的是这意味着安装编译器和包管理器。要验证是否已安装所有内容,请运行以下命令:
|
安装`rustup`将安装与rust相关的所有内容,但最重要的是这意味着安装编译器和包管理器。要验证是否已安装所有内容,请运行以下命令:
|
||||||
安装`rustup`将安装与rust相关的所有内容,但最重要的是这意味着安装编译器和包管理器。要验证是否已安装所有内容,请运行以下命令:
|
```shell
|
||||||
|
|
||||||
cargo version
|
cargo version
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -31,4 +30,4 @@ cargo version
|
|||||||
|
|
||||||
# 更多信息
|
# 更多信息
|
||||||
|
|
||||||
|
要了解有关安装过程的更多信息,请访问 https://www.rust-lang.org/en-US/install.html
|
||||||
|
@ -126,7 +126,7 @@ obj_0 = MyClass()
|
|||||||
|
|
||||||
## iOS中的Singleton
|
## iOS中的Singleton
|
||||||
|
|
||||||
```Swift4
|
```swift
|
||||||
class Singleton {
|
class Singleton {
|
||||||
static let sharedInstance = Singleton()
|
static let sharedInstance = Singleton()
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ The red square is the starting point and the gray squares are the so called wall
|
|||||||
For further details, here's a piece of code describing the function:
|
For further details, here's a piece of code describing the function:
|
||||||
|
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
|
|
||||||
int wall = -1;
|
int wall = -1;
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ to island x.
|
|||||||
**Ex:**
|
**Ex:**
|
||||||
|
|
||||||
You have the following input:
|
You have the following input:
|
||||||
```c++
|
```cpp
|
||||||
2 4 4
|
2 4 4
|
||||||
0 0 0 1
|
0 0 0 1
|
||||||
0 0 1 1
|
0 0 1 1
|
||||||
|
@ -23,7 +23,7 @@ your own version of queue.
|
|||||||
|
|
||||||
C++ code:
|
C++ code:
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
|
|
||||||
int dl[] = {-1, 0, 1, 0}; // these arrays will help you travel in the 4 directions more easily
|
int dl[] = {-1, 0, 1, 0}; // these arrays will help you travel in the 4 directions more easily
|
||||||
int dc[] = {0, 1, 0, -1};
|
int dc[] = {0, 1, 0, -1};
|
||||||
|
@ -200,7 +200,7 @@ def binary_search(arr, l, r, target):
|
|||||||
|
|
||||||
Recursive approach!
|
Recursive approach!
|
||||||
|
|
||||||
```C++ -
|
```cpp
|
||||||
// Recursive approach in C++
|
// Recursive approach in C++
|
||||||
int binarySearch(int arr[], int start, int end, int x)
|
int binarySearch(int arr[], int start, int end, int x)
|
||||||
{
|
{
|
||||||
@ -221,7 +221,7 @@ int binarySearch(int arr[], int start, int end, int x)
|
|||||||
|
|
||||||
Iterative approach!
|
Iterative approach!
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
int binarySearch(int arr[], int start, int end, int x)
|
int binarySearch(int arr[], int start, int end, int x)
|
||||||
{
|
{
|
||||||
while (start <= end)
|
while (start <= end)
|
||||||
|
@ -88,7 +88,7 @@ end
|
|||||||
```
|
```
|
||||||
### Example in C++
|
### Example in C++
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
int linear_search(int arr[],int n,int num)
|
int linear_search(int arr[],int n,int num)
|
||||||
{
|
{
|
||||||
for(int i=0;i<n;i++){
|
for(int i=0;i<n;i++){
|
||||||
@ -121,7 +121,7 @@ func linearSearch(for number: Int, in array: [Int]) -> Int? {
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Example in Java
|
### Example in Java
|
||||||
```Java 8
|
```java
|
||||||
int linearSearch(int[] arr, int element)
|
int linearSearch(int[] arr, int element)
|
||||||
{
|
{
|
||||||
for(int i=0;i<arr.length;i++)
|
for(int i=0;i<arr.length;i++)
|
||||||
|
@ -85,7 +85,7 @@ Step 5 :
|
|||||||
|
|
||||||
The algorithm shown below is a slightly optimized version to avoid swapping the `key` element in every iteration. Here, the `key` element will be swapped at the end of the iteration (step).
|
The algorithm shown below is a slightly optimized version to avoid swapping the `key` element in every iteration. Here, the `key` element will be swapped at the end of the iteration (step).
|
||||||
|
|
||||||
```Algorithm
|
```
|
||||||
InsertionSort(arr[])
|
InsertionSort(arr[])
|
||||||
for j = 1 to arr.length
|
for j = 1 to arr.length
|
||||||
key = arr[j]
|
key = arr[j]
|
||||||
|
@ -27,7 +27,7 @@ __P =__ egef
|
|||||||
The last occurrence function can be stored as an array indexed by the numeric codes of the characters. This function can be calculated in O(m+s) time where m is the length of the pattern and s the size of the alphabet.
|
The last occurrence function can be stored as an array indexed by the numeric codes of the characters. This function can be calculated in O(m+s) time where m is the length of the pattern and s the size of the alphabet.
|
||||||
|
|
||||||
### Code of Boyer-Moore Algorithm in C++
|
### Code of Boyer-Moore Algorithm in C++
|
||||||
```c++
|
```cpp
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
#define MAXCHAR 256 //there are 256 ASCII characters
|
#define MAXCHAR 256 //there are 256 ASCII characters
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -66,12 +66,12 @@ The `-R` flag will cause grep to search recursively through the `/etc` directory
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### Start Apache
|
#### Start Apache
|
||||||
```sh
|
```shell
|
||||||
sudo systemctl start httpd
|
sudo systemctl start httpd
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Run Apache on Startup
|
#### Run Apache on Startup
|
||||||
```sh
|
```shell
|
||||||
sudo systemctl enable httpd
|
sudo systemctl enable httpd
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -96,12 +96,12 @@ If you want to host multiple domains on a single server, you can configure Virtu
|
|||||||
You can copy the `default.conf` and modify accordingly in the following directory:
|
You can copy the `default.conf` and modify accordingly in the following directory:
|
||||||
|
|
||||||
#### On Ubuntu:
|
#### On Ubuntu:
|
||||||
```sh
|
```shell
|
||||||
/etc/apache2/sites-enabled/
|
/etc/apache2/sites-enabled/
|
||||||
```
|
```
|
||||||
|
|
||||||
#### On Centos:
|
#### On Centos:
|
||||||
```sh
|
```shell
|
||||||
/etc/httpd/sites-enabled/
|
/etc/httpd/sites-enabled/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ There are several ways to get started with Bulma.
|
|||||||
* Use the <b>GitHub Repository</b> to get the latest development version.
|
* Use the <b>GitHub Repository</b> to get the latest development version.
|
||||||
|
|
||||||
1) Using npm
|
1) Using npm
|
||||||
```terminal
|
```shell
|
||||||
$ npm install bulma
|
$ npm install bulma
|
||||||
```
|
```
|
||||||
2) Use the cdnjs CDN
|
2) Use the cdnjs CDN
|
||||||
|
@ -328,7 +328,7 @@ void main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
The output becomes
|
The output becomes
|
||||||
```output
|
```shell
|
||||||
The value of integer variable is = 10
|
The value of integer variable is = 10
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ title: Add a License to Your package.json
|
|||||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||||
You should go over to the `package.json` file in your project. Licenses follow a similar convention as this:
|
You should go over to the `package.json` file in your project. Licenses follow a similar convention as this:
|
||||||
|
|
||||||
```code
|
```json
|
||||||
"license": "ExampleLicense"
|
"license": "ExampleLicense"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ title: Add a Version to Your package.json
|
|||||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||||
You should go over to the package.json file in your project. Versions follow a similar convention as this:
|
You should go over to the package.json file in your project. Versions follow a similar convention as this:
|
||||||
|
|
||||||
```code
|
```json
|
||||||
"version": "x.x.x"
|
"version": "x.x.x"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ title: Expand Your Project with External Packages from npm
|
|||||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||||
You should go over to the `package.json` file in your project. Dependencies follow a similar convention as this:
|
You should go over to the `package.json` file in your project. Dependencies follow a similar convention as this:
|
||||||
|
|
||||||
```code
|
```json
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
"helmet": "^3.14.0"
|
"helmet": "^3.14.0"
|
||||||
|
@ -6,7 +6,7 @@ title: Manage npm Dependencies By Understanding Semantic Versioning
|
|||||||
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
|
||||||
You should go over to the `package.json` file in your project. SemVer dependencies follow a similar convention like this:
|
You should go over to the `package.json` file in your project. SemVer dependencies follow a similar convention like this:
|
||||||
|
|
||||||
```code
|
```json
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dependency1": "^major.minor.patch"
|
"dependency1": "^major.minor.patch"
|
||||||
},
|
},
|
||||||
|
@ -7,7 +7,7 @@ title: Remove a Package from Your Dependencies
|
|||||||
You should go over to the `package.json` file in your project. Removing a package is as simple as going into your dependencies section and removing the line with the corresponding item. In the following example "express" is removed from `package.json`:
|
You should go over to the `package.json` file in your project. Removing a package is as simple as going into your dependencies section and removing the line with the corresponding item. In the following example "express" is removed from `package.json`:
|
||||||
|
|
||||||
Before
|
Before
|
||||||
```code
|
```json
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
"helmet": "^3.14.0"
|
"helmet": "^3.14.0"
|
||||||
@ -15,7 +15,7 @@ Before
|
|||||||
```
|
```
|
||||||
|
|
||||||
After
|
After
|
||||||
```code
|
```json
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
},
|
},
|
||||||
|
@ -10,25 +10,25 @@ title: Create a Circular Queue
|
|||||||
- The dequeue method on the other hand, moves the read pointer but doesnt exceed the write pointer.
|
- The dequeue method on the other hand, moves the read pointer but doesnt exceed the write pointer.
|
||||||
- Example:
|
- Example:
|
||||||
- First, we create an array of length 5:
|
- First, we create an array of length 5:
|
||||||
```output
|
```shell
|
||||||
[null, null, null, null, null]
|
[null, null, null, null, null]
|
||||||
^Read @ 0
|
^Read @ 0
|
||||||
^Write @ 0
|
^Write @ 0
|
||||||
```
|
```
|
||||||
- Then we enqueue `a`, `b`, and `c`:
|
- Then we enqueue `a`, `b`, and `c`:
|
||||||
```output
|
```shell
|
||||||
[a, b, c, null, null]
|
[a, b, c, null, null]
|
||||||
^Read @ 0
|
^Read @ 0
|
||||||
^Write @ 3
|
^Write @ 3
|
||||||
```
|
```
|
||||||
- Now we dequeue all the enqueued items:
|
- Now we dequeue all the enqueued items:
|
||||||
```output
|
```shell
|
||||||
[null, null, null, null, null]
|
[null, null, null, null, null]
|
||||||
^Read @ 3
|
^Read @ 3
|
||||||
^Write @ 3
|
^Write @ 3
|
||||||
```
|
```
|
||||||
- Finally, we enqueue `d`, `e` and `f`:
|
- Finally, we enqueue `d`, `e` and `f`:
|
||||||
```output
|
```shell
|
||||||
[f, null, null, d, e]
|
[f, null, null, d, e]
|
||||||
^Read @ 3
|
^Read @ 3
|
||||||
^Write @ 1
|
^Write @ 1
|
||||||
|
@ -59,7 +59,7 @@ class GateKeeper extends React.Component {
|
|||||||
## Solution
|
## Solution
|
||||||
Write a conditional statement that is evaluated according to your state, as mentioned in the challenge description, checks the length of the input and assigns a new object to the inputStyle variable.
|
Write a conditional statement that is evaluated according to your state, as mentioned in the challenge description, checks the length of the input and assigns a new object to the inputStyle variable.
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
if (this.state.input.length > 15) {
|
if (this.state.input.length > 15) {
|
||||||
inputStyle = {
|
inputStyle = {
|
||||||
border: '3px solid red'
|
border: '3px solid red'
|
||||||
|
@ -9,12 +9,12 @@ First, create a controlled input that stores its value in state, so that there i
|
|||||||
(This is what you did in the previous challenge.) Create an input element, set its value attribute to the input variable located in state. Remember, state can be accessed by `this.state`. Next, set the input element's `onChange` attribute to call the function 'handleChange'.
|
(This is what you did in the previous challenge.) Create an input element, set its value attribute to the input variable located in state. Remember, state can be accessed by `this.state`. Next, set the input element's `onChange` attribute to call the function 'handleChange'.
|
||||||
|
|
||||||
### Solution
|
### Solution
|
||||||
```react.js
|
```jsx
|
||||||
<input value={this.state.input} onChange={this.handleChange}/>
|
<input value={this.state.input} onChange={this.handleChange}/>
|
||||||
```
|
```
|
||||||
|
|
||||||
Next, create the handleSubmit method for your component. First, because your form is submitting you will have to prevent the page from refreshing. Second, call the `setState()` method, passing in an object of the different key-value pairs that you want to change. In this case, you want to set 'submit' to the value of the variable 'input' and set 'input' to an empty string.
|
Next, create the handleSubmit method for your component. First, because your form is submitting you will have to prevent the page from refreshing. Second, call the `setState()` method, passing in an object of the different key-value pairs that you want to change. In this case, you want to set 'submit' to the value of the variable 'input' and set 'input' to an empty string.
|
||||||
```react.js
|
```jsx
|
||||||
handleSubmit(event) {
|
handleSubmit(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.setState({
|
this.setState({
|
||||||
|
@ -8,7 +8,7 @@ It is just almost same as previous [challenge](https://learn.freecodecamp.org/fr
|
|||||||
## Solution
|
## Solution
|
||||||
Just add `key` attribute to the `<li>` tag to make unique
|
Just add `key` attribute to the `<li>` tag to make unique
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
const renderFrameworks = frontEndFrameworks.map((item) =>
|
const renderFrameworks = frontEndFrameworks.map((item) =>
|
||||||
<li key={item+1}>{item}</li>
|
<li key={item+1}>{item}</li>
|
||||||
);
|
);
|
||||||
|
@ -9,7 +9,7 @@ This one can be a little tricky because JSX is very similar to HTML but **NOT th
|
|||||||
Let's walkthrough the steps so that you understand the difference.
|
Let's walkthrough the steps so that you understand the difference.
|
||||||
First set your style tag to a **JavaScript object**.
|
First set your style tag to a **JavaScript object**.
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
class Colorful extends React.Component {
|
class Colorful extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -24,7 +24,7 @@ Now you have your style tag set to an empty object. Notice how there are two set
|
|||||||
|
|
||||||
Second, let's set the color to red.
|
Second, let's set the color to red.
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
class Colorful extends React.Component {
|
class Colorful extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
@ -39,7 +39,7 @@ class Colorful extends React.Component {
|
|||||||
Finally, let's set the font size to 72px.
|
Finally, let's set the font size to 72px.
|
||||||
|
|
||||||
### Spoiler
|
### Spoiler
|
||||||
```react.js
|
```jsx
|
||||||
class Colorful extends React.Component {
|
class Colorful extends React.Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
@ -3,7 +3,7 @@ title: Override Default Props
|
|||||||
---
|
---
|
||||||
## Override Default Props
|
## Override Default Props
|
||||||
This challenge has you override the default value of props `quantity` for the Items component. Where default value of `quantity` is set to `0`.
|
This challenge has you override the default value of props `quantity` for the Items component. Where default value of `quantity` is set to `0`.
|
||||||
```react.js
|
```jsx
|
||||||
const Items = (props) => {
|
const Items = (props) => {
|
||||||
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
|
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
|
||||||
}
|
}
|
||||||
@ -13,12 +13,12 @@ Items.defaultProps = {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
To override a default props value, the syntax to be followed is
|
To override a default props value, the syntax to be followed is
|
||||||
```react.js
|
```jsx
|
||||||
<Component propsName={Value}/>
|
<Component propsName={Value}/>
|
||||||
```
|
```
|
||||||
|
|
||||||
Following the Syntax, the following code should be declared below the given code
|
Following the Syntax, the following code should be declared below the given code
|
||||||
```react.js
|
```jsx
|
||||||
<Items quantity={50}/>
|
<Items quantity={50}/>
|
||||||
```
|
```
|
||||||
This will override value `0` to `50`
|
This will override value `0` to `50`
|
||||||
|
@ -7,7 +7,7 @@ This is a bit tricky challenge but easy though.
|
|||||||
## Solution
|
## Solution
|
||||||
Change `handleClick()` with proper increment statement.
|
Change `handleClick()` with proper increment statement.
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
handleClick() {
|
handleClick() {
|
||||||
this.setState({
|
this.setState({
|
||||||
counter: this.state.counter + 1
|
counter: this.state.counter + 1
|
||||||
@ -15,7 +15,7 @@ handleClick() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
In `render()` method use `Math.random()` as mentioned in the challenge description and write a ternary expression to pass `props` in the **Results** component.
|
In `render()` method use `Math.random()` as mentioned in the challenge description and write a ternary expression to pass `props` in the **Results** component.
|
||||||
```react.js
|
```jsx
|
||||||
let expression = Math.random() > .5;
|
let expression = Math.random() > .5;
|
||||||
|
|
||||||
{(expression == 1)? <Results fiftyFifty="You win!"/> : <Results fiftyFifty="You lose!"/> }
|
{(expression == 1)? <Results fiftyFifty="You win!"/> : <Results fiftyFifty="You lose!"/> }
|
||||||
@ -23,7 +23,7 @@ In `render()` method use `Math.random()` as mentioned in the challenge descripti
|
|||||||
```
|
```
|
||||||
|
|
||||||
Then render the `fiftyFifty` props in the Results component.
|
Then render the `fiftyFifty` props in the Results component.
|
||||||
```react.js
|
```jsx
|
||||||
<h1>
|
<h1>
|
||||||
{
|
{
|
||||||
this.props.fiftyFifty
|
this.props.fiftyFifty
|
||||||
|
@ -10,7 +10,7 @@ Just make a `<h1>` tag and render `this.state.name` between tag.
|
|||||||
|
|
||||||
## Solution
|
## Solution
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
class MyComponent extends React.Component {
|
class MyComponent extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
@ -9,7 +9,7 @@ Inside of the render method of the component, write if/else statements that each
|
|||||||
First, wrap the current return method inside of an if statement and set the condition to check if the variable 'display' is true. Remember, you access state using `this.state`.
|
First, wrap the current return method inside of an if statement and set the condition to check if the variable 'display' is true. Remember, you access state using `this.state`.
|
||||||
|
|
||||||
### Solution
|
### Solution
|
||||||
```react.js
|
```jsx
|
||||||
if (this.state.display === true) {
|
if (this.state.display === true) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -21,7 +21,7 @@ if (this.state.display === true) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Next, create an else statement that returns the same JSX **without** the `h1` element.
|
Next, create an else statement that returns the same JSX **without** the `h1` element.
|
||||||
```react.js
|
```jsx
|
||||||
else {
|
else {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
@ -13,7 +13,7 @@ condition ? expressionIfTrue : expressionIfFalse
|
|||||||
Here is sample solution of using ternary expression.
|
Here is sample solution of using ternary expression.
|
||||||
First you need declare state in constructor like this
|
First you need declare state in constructor like this
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
// change code below this line
|
// change code below this line
|
||||||
@ -27,7 +27,7 @@ constructor(props) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
Then the ternary operator
|
Then the ternary operator
|
||||||
```react.js
|
```jsx
|
||||||
{
|
{
|
||||||
/* change code here */
|
/* change code here */
|
||||||
(this.state.userAge >= 18) ? buttonTwo : (this.state.userAge== '')? buttonOne: buttonThree
|
(this.state.userAge >= 18) ? buttonTwo : (this.state.userAge== '')? buttonOne: buttonThree
|
||||||
|
@ -4,21 +4,21 @@ title: Use PropTypes to Define the Props You Expect
|
|||||||
## Use PropTypes to Define the Props You Expect
|
## Use PropTypes to Define the Props You Expect
|
||||||
|
|
||||||
This challenge has you set a `propTypes` for the `Items` component.
|
This challenge has you set a `propTypes` for the `Items` component.
|
||||||
```react.js
|
```jsx
|
||||||
const Items = (props) => {
|
const Items = (props) => {
|
||||||
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
|
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
To set a propTypes, the syntax to be followed is
|
To set a propTypes, the syntax to be followed is
|
||||||
```react.js
|
```jsx
|
||||||
itemName.propTypes = {
|
itemName.propTypes = {
|
||||||
props: PropTypes.dataType.isRequired
|
props: PropTypes.dataType.isRequired
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
Following the Syntax, the following code should be set below the given code for the `quantity` props of `Items` component
|
Following the Syntax, the following code should be set below the given code for the `quantity` props of `Items` component
|
||||||
```react.js
|
```jsx
|
||||||
Items.propTypes = {
|
Items.propTypes = {
|
||||||
quantity: PropTypes.number.isRequired
|
quantity: PropTypes.number.isRequired
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,7 @@ title: Define a Redux Action
|
|||||||
## Define a Redux Action
|
## Define a Redux Action
|
||||||
|
|
||||||
Here is how to declare a Redux Action.
|
Here is how to declare a Redux Action.
|
||||||
```react.js
|
```jsx
|
||||||
let action={
|
let action={
|
||||||
type: 'LOGIN'
|
type: 'LOGIN'
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,6 @@ title: Dispatch an Action Event
|
|||||||
|
|
||||||
Dispatch the LOGIN action to the Redux store by calling the dispatch method, and pass in the action created by `loginAction()`.
|
Dispatch the LOGIN action to the Redux store by calling the dispatch method, and pass in the action created by `loginAction()`.
|
||||||
|
|
||||||
```react.js
|
```jsx
|
||||||
store.dispatch(loginAction());
|
store.dispatch(loginAction());
|
||||||
```
|
```
|
||||||
|
@ -4,6 +4,6 @@ title: Get State from the Redux Store
|
|||||||
## Get State from the Redux Store
|
## Get State from the Redux Store
|
||||||
|
|
||||||
Retrieve data from store by using `getState()` method.
|
Retrieve data from store by using `getState()` method.
|
||||||
```react.js
|
```jsx
|
||||||
let currentState = store.getState();
|
let currentState = store.getState();
|
||||||
```
|
```
|
||||||
|
@ -14,7 +14,7 @@ Inside the string literal, place the pet names, each seperated by the `|` symbol
|
|||||||
|
|
||||||
## Solution:
|
## Solution:
|
||||||
|
|
||||||
```javascriot
|
```js
|
||||||
let petString = "James has a pet cat.";
|
let petString = "James has a pet cat.";
|
||||||
let petRegex = /dog|cat|bird|fish/;
|
let petRegex = /dog|cat|bird|fish/;
|
||||||
let result = petRegex.test(petString);
|
let result = petRegex.test(petString);
|
||||||
|
@ -8,7 +8,8 @@ Use the shorthand character class \w to count the number of alphanumeric charact
|
|||||||
|
|
||||||
## Solution
|
## Solution
|
||||||
|
|
||||||
```let quoteSample = "The five boxing wizards jump quickly.";
|
```js
|
||||||
|
let quoteSample = "The five boxing wizards jump quickly.";
|
||||||
let alphabetRegexV2 = /\w/gi; // Change this line
|
let alphabetRegexV2 = /\w/gi; // Change this line
|
||||||
let result = quoteSample.match(alphabetRegexV2).length;
|
let result = quoteSample.match(alphabetRegexV2).length;
|
||||||
```
|
```
|
||||||
|
@ -16,7 +16,7 @@ If so, then double check you're adding the appropriate flags:
|
|||||||
|
|
||||||
### Hint 2:
|
### Hint 2:
|
||||||
Be sure to check whether your number range is correct -- the challenge asks us to negate all numbers from 0 to 9. This can be done using the negate caret placed immediately after the first opening bracket of your regexp.
|
Be sure to check whether your number range is correct -- the challenge asks us to negate all numbers from 0 to 9. This can be done using the negate caret placed immediately after the first opening bracket of your regexp.
|
||||||
```javacsript
|
```js
|
||||||
let numbersRegExp = /[^0-9]/ig;
|
let numbersRegExp = /[^0-9]/ig;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ A forest is a set of n ≥ 0 disjoint trees.
|
|||||||
|
|
||||||
### Code of a tree node
|
### Code of a tree node
|
||||||
|
|
||||||
``` c++
|
```cpp
|
||||||
struct node
|
struct node
|
||||||
{
|
{
|
||||||
int data; //Data element
|
int data; //Data element
|
||||||
@ -105,7 +105,7 @@ struct node
|
|||||||
### Code for node creation
|
### Code for node creation
|
||||||
createNode() returns a new node with the given data and NULL left and right pointers.
|
createNode() returns a new node with the given data and NULL left and right pointers.
|
||||||
|
|
||||||
``` c++
|
```cpp
|
||||||
struct node* newNode(int element)
|
struct node* newNode(int element)
|
||||||
{
|
{
|
||||||
struct node* temp = (node*)malloc(sizeof(node)); //Allocate memeory for temp node
|
struct node* temp = (node*)malloc(sizeof(node)); //Allocate memeory for temp node
|
||||||
|
@ -12,7 +12,7 @@ The try-catch statement consists of a **try** block and a **catch** block and an
|
|||||||
|
|
||||||
Below is an example program that handles the divide by zero exception using predefined class in C# library. Exception is the base class for all the exceptions.
|
Below is an example program that handles the divide by zero exception using predefined class in C# library. Exception is the base class for all the exceptions.
|
||||||
|
|
||||||
```c#
|
```csharp
|
||||||
using System;
|
using System;
|
||||||
namespace ErrorHandling
|
namespace ErrorHandling
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,6 @@ docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
|
|||||||
```
|
```
|
||||||
# Examples
|
# Examples
|
||||||
Create and start a container
|
Create and start a container
|
||||||
```sh
|
```shell
|
||||||
$ docker create -t -i fedora bash
|
$ docker create -t -i fedora bash
|
||||||
```
|
```
|
||||||
|
@ -15,7 +15,7 @@ For loop is an entry controlled loop unlike do-while loop.
|
|||||||
|
|
||||||
## Syntax
|
## Syntax
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
for (init; condition; increment ) {
|
for (init; condition; increment ) {
|
||||||
update_statement(s);
|
update_statement(s);
|
||||||
}
|
}
|
||||||
@ -23,7 +23,7 @@ for (init; condition; increment ) {
|
|||||||
|
|
||||||
The increment can also placed inside the for loop i.e. in its body-
|
The increment can also placed inside the for loop i.e. in its body-
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
for ( init; condition;) {
|
for ( init; condition;) {
|
||||||
update_statement(s);
|
update_statement(s);
|
||||||
increment;
|
increment;
|
||||||
@ -32,7 +32,7 @@ for ( init; condition;) {
|
|||||||
|
|
||||||
It is also allowed to ignore the init variables if and only if they are declared beforehand. For example :
|
It is also allowed to ignore the init variables if and only if they are declared beforehand. For example :
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
int a = 1;
|
int a = 1;
|
||||||
for (; a <= 10 ;) {
|
for (; a <= 10 ;) {
|
||||||
cout << a << '\n';
|
cout << a << '\n';
|
||||||
@ -58,7 +58,7 @@ The update statement is used to alter the loop variable by using simple operatio
|
|||||||
You will often see an increment operation as the update statement (e.g. i++, count++). This is often seen as one of the distinguishing features and possible name sources for the C++ language.
|
You will often see an increment operation as the update statement (e.g. i++, count++). This is often seen as one of the distinguishing features and possible name sources for the C++ language.
|
||||||
|
|
||||||
## Implementation
|
## Implementation
|
||||||
```c++
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using std::cout; // Here we use the scope resolution operator to define the scope of the standard functions as std
|
using std::cout; // Here we use the scope resolution operator to define the scope of the standard functions as std
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@ -74,7 +74,7 @@ int main () {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
```output
|
```shell
|
||||||
value of a: 10
|
value of a: 10
|
||||||
value of a: 11
|
value of a: 11
|
||||||
value of a: 12
|
value of a: 12
|
||||||
@ -91,7 +91,7 @@ value of a: 19
|
|||||||
The body of the for loop need not be enclosed in braces if the loop iterates over only one statement.
|
The body of the for loop need not be enclosed in braces if the loop iterates over only one statement.
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
```c++
|
```cpp
|
||||||
#include<iostream.h>
|
#include<iostream.h>
|
||||||
using std::cout;
|
using std::cout;
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ int main () {
|
|||||||
This would generate the same output as the previous program.
|
This would generate the same output as the previous program.
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
```output
|
```shell
|
||||||
value of a: 10
|
value of a: 10
|
||||||
value of a: 11
|
value of a: 11
|
||||||
value of a: 12
|
value of a: 12
|
||||||
@ -128,13 +128,13 @@ C++ also has what we call "range-based" `for` loops which iterate through all th
|
|||||||
|
|
||||||
### Syntax
|
### Syntax
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
for ( element: container ) {
|
for ( element: container ) {
|
||||||
statement(s);
|
statement(s);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```c++
|
```cpp
|
||||||
int[5] array = { 1, 2, 3, 4, 5 }
|
int[5] array = { 1, 2, 3, 4, 5 }
|
||||||
for ( int i: array ) {
|
for ( int i: array ) {
|
||||||
cout << i << endl;
|
cout << i << endl;
|
||||||
@ -142,7 +142,7 @@ for ( int i: array ) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Output:
|
Output:
|
||||||
```output
|
```shell
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
3
|
3
|
||||||
@ -154,7 +154,7 @@ Output:
|
|||||||
Iterator based for loops are also possible in C++ and functionality for them exists in many of the data structures found within the STL. Unlike for-each loops, iterator based loops allow for mutating the contents of the container during iteration. This is rather useful when one needs to remove or insert values while looping over data.
|
Iterator based for loops are also possible in C++ and functionality for them exists in many of the data structures found within the STL. Unlike for-each loops, iterator based loops allow for mutating the contents of the container during iteration. This is rather useful when one needs to remove or insert values while looping over data.
|
||||||
|
|
||||||
### Syntax
|
### Syntax
|
||||||
```c++
|
```cpp
|
||||||
// Create a vector
|
// Create a vector
|
||||||
std::vector<int> vec;
|
std::vector<int> vec;
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ for(std::vector<string>::iterator it = vec.begin(); it != vec.end(); it++) {
|
|||||||
### Use as infinite loops
|
### Use as infinite loops
|
||||||
|
|
||||||
This C-style for-loop is commonly the source of an infinite loop since the fundamental steps of iteration are completely in the control of the programmer. In fact, when infinite loops are intended, this type of for-loop can be used (with empty expressions), such as:
|
This C-style for-loop is commonly the source of an infinite loop since the fundamental steps of iteration are completely in the control of the programmer. In fact, when infinite loops are intended, this type of for-loop can be used (with empty expressions), such as:
|
||||||
```c++
|
```cpp
|
||||||
for (;;) {
|
for (;;) {
|
||||||
//loop body
|
//loop body
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ Traversal in a list is slow as compared to Vectors and Arrays, but once a positi
|
|||||||
## How to declare a List
|
## How to declare a List
|
||||||
|
|
||||||
Possible declarations of a list:
|
Possible declarations of a list:
|
||||||
```c++
|
```cpp
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@ -9,7 +9,7 @@ title: Loops
|
|||||||
Now let's discuss something known as loop. Suppose you want to print the even numbers from 1 to 1000 on the screen. One way
|
Now let's discuss something known as loop. Suppose you want to print the even numbers from 1 to 1000 on the screen. One way
|
||||||
to do this is to write the following lines
|
to do this is to write the following lines
|
||||||
|
|
||||||
``` c++
|
```cpp
|
||||||
cout << 0 << endl;
|
cout << 0 << endl;
|
||||||
cout << 2 << endl;
|
cout << 2 << endl;
|
||||||
cout << 4 << endl;
|
cout << 4 << endl;
|
||||||
@ -30,7 +30,7 @@ While and do while loops allow you to run the loop until a condition finishes.
|
|||||||
The difference between While and Do while is that Do while loop always executes at least once.
|
The difference between While and Do while is that Do while loop always executes at least once.
|
||||||
The very use of Do while loop can be seen in the scenarios when the number of times that the loop will run depends upon the first iteration of the loop.
|
The very use of Do while loop can be seen in the scenarios when the number of times that the loop will run depends upon the first iteration of the loop.
|
||||||
Here you can see an example:
|
Here you can see an example:
|
||||||
``` c++
|
```cpp
|
||||||
while (condition){
|
while (condition){
|
||||||
// Code that will execute while condition is true
|
// Code that will execute while condition is true
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ For loops are usually used when you know how many times the code will execute.
|
|||||||
The flow can be seen in this [graph](https://www.tutorialspoint.com/cplusplus/images/cpp_for_loop.jpg).
|
The flow can be seen in this [graph](https://www.tutorialspoint.com/cplusplus/images/cpp_for_loop.jpg).
|
||||||
|
|
||||||
They are declared this way:
|
They are declared this way:
|
||||||
``` c++
|
```cpp
|
||||||
for ( initialize a variable; check a condition; increment the initialized variable ) {
|
for ( initialize a variable; check a condition; increment the initialized variable ) {
|
||||||
//Code to execute
|
//Code to execute
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ for ( initialize a variable; check a condition; increment the initialized variab
|
|||||||
|
|
||||||
Let's write a program which will print numbers from 0 to 1000 including 1000 on the screen using a for loop.
|
Let's write a program which will print numbers from 0 to 1000 including 1000 on the screen using a for loop.
|
||||||
|
|
||||||
``` c++
|
```cpp
|
||||||
for (int i = 0;i<=1000;i++)
|
for (int i = 0;i<=1000;i++)
|
||||||
{
|
{
|
||||||
cout << i << endl;
|
cout << i << endl;
|
||||||
@ -77,7 +77,7 @@ Now let's discuss how the for loop works.
|
|||||||
` for(int i=0;i<=1000;i++) `
|
` for(int i=0;i<=1000;i++) `
|
||||||
* If there is only one statement inside the loop then the curly bracket is optional but its better to write loop code
|
* If there is only one statement inside the loop then the curly bracket is optional but its better to write loop code
|
||||||
within brackets so that you don't get confused.
|
within brackets so that you don't get confused.
|
||||||
``` c++
|
```cpp
|
||||||
for(int i=0;i<=1000;i++)
|
for(int i=0;i<=1000;i++)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ Now let's discuss how the for loop works.
|
|||||||
|
|
||||||
If you want to print even numbers from 1 to 1000 then your program will look like this:
|
If you want to print even numbers from 1 to 1000 then your program will look like this:
|
||||||
|
|
||||||
``` c++
|
```cpp
|
||||||
for (int i = 0;i<=1000;i=i+2)
|
for (int i = 0;i<=1000;i=i+2)
|
||||||
{
|
{
|
||||||
cout << i << endl;
|
cout << i << endl;
|
||||||
@ -100,7 +100,7 @@ for (int i = 0;i<=1000;i=i+2)
|
|||||||
|
|
||||||
Our next program to print even numbers from 0 to 1000 will look like this:
|
Our next program to print even numbers from 0 to 1000 will look like this:
|
||||||
|
|
||||||
``` c++
|
```cpp
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
int main()
|
int main()
|
||||||
@ -114,7 +114,7 @@ int main()
|
|||||||
```
|
```
|
||||||
Another type of for loop is the [Range-based for loop](https://en.cppreference.com/w/cpp/language/range-for).
|
Another type of for loop is the [Range-based for loop](https://en.cppreference.com/w/cpp/language/range-for).
|
||||||
|
|
||||||
``` c++
|
```cpp
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
int main()
|
int main()
|
||||||
|
@ -146,7 +146,8 @@ int main ()
|
|||||||
Returns whether the `queue` is empty ,i.e. whether your queue size is zero.
|
Returns whether the `queue` is empty ,i.e. whether your queue size is zero.
|
||||||
It returns `true` if queue's size 0 else returns `false`
|
It returns `true` if queue's size 0 else returns `false`
|
||||||
|
|
||||||
```cpp//Empty operation in Queue
|
```cpp
|
||||||
|
//Empty operation in Queue
|
||||||
#include <iostream> // std::cout
|
#include <iostream> // std::cout
|
||||||
#include <queue> // std::stack
|
#include <queue> // std::stack
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ Two case labels cannot have the same value.
|
|||||||
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```C++
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ title: While-loop
|
|||||||
A while loop statement repeatedly executes a target statement as long as a given condition is true. It is often used when the number of iterations is unknown.
|
A while loop statement repeatedly executes a target statement as long as a given condition is true. It is often used when the number of iterations is unknown.
|
||||||
|
|
||||||
Syntax:
|
Syntax:
|
||||||
```C++
|
```cpp
|
||||||
while(condition) {
|
while(condition) {
|
||||||
statement(s);
|
statement(s);
|
||||||
}
|
}
|
||||||
@ -18,7 +18,7 @@ Another important point about the while loop is to remember to increment/decreme
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
```C++
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ value of a: 19
|
|||||||
```
|
```
|
||||||
|
|
||||||
Example of Skipped Loop Body:
|
Example of Skipped Loop Body:
|
||||||
```C++
|
```cpp
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ namespace CPrograms
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Output:
|
## Output:
|
||||||
```sh
|
```shell
|
||||||
> Employee Name: John Doe, Employee ID: 420156
|
> Employee Name: John Doe, Employee ID: 420156
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ foreach(string name in Names)
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Output:
|
### Output:
|
||||||
```sh
|
```shell
|
||||||
> We have Jim
|
> We have Jim
|
||||||
> We have Jane
|
> We have Jane
|
||||||
> We have Jack
|
> We have Jack
|
||||||
|
@ -31,7 +31,7 @@ namespace HelloWorld
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Output:
|
## Output:
|
||||||
```sh
|
```shell
|
||||||
> Hello World!
|
> Hello World!
|
||||||
> Press any key to exit.
|
> Press any key to exit.
|
||||||
```
|
```
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user