mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-15 22:57:48 +08:00
Add ru version (#1865)
* Add Russian docs site baseline * Add Russian localized codebase * Polish Russian code wording * Update ru code translation. * Update code translation and chapter covers. * Fix pythontutor extraction. * Add README and landing page. * placeholder of profiles * Use figures of English version * Remove chapter paperbook
This commit is contained in:
35
ru/codes/javascript/chapter_stack_and_queue/queue.js
Normal file
35
ru/codes/javascript/chapter_stack_and_queue/queue.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* File: queue.js
|
||||
* Created Time: 2022-12-05
|
||||
* Author: S-N-O-R-L-A-X (snorlax.xu@outlook.com)
|
||||
*/
|
||||
|
||||
/* Driver Code */
|
||||
/* Инициализация очереди */
|
||||
// В JavaScript нет встроенной очереди, поэтому Array можно использовать как очередь
|
||||
const queue = [];
|
||||
|
||||
/* Добавление элемента в очередь */
|
||||
queue.push(1);
|
||||
queue.push(3);
|
||||
queue.push(2);
|
||||
queue.push(5);
|
||||
queue.push(4);
|
||||
console.log('Очередь queue =', queue);
|
||||
|
||||
/* Доступ к элементу в начале очереди */
|
||||
const peek = queue[0];
|
||||
console.log('Первый элемент peek =', peek);
|
||||
|
||||
/* Извлечение элемента из очереди */
|
||||
// В основе лежит массив, поэтому временная сложность метода shift() равна O(n)
|
||||
const pop = queue.shift();
|
||||
console.log('Извлеченный элемент pop =', pop, ', queue после извлечения = ', queue);
|
||||
|
||||
/* Получение длины очереди */
|
||||
const size = queue.length;
|
||||
console.log('Длина очереди size =', size);
|
||||
|
||||
/* Проверка, пуста ли очередь */
|
||||
const isEmpty = queue.length === 0;
|
||||
console.log('Пуста ли очередь = ', isEmpty);
|
||||
Reference in New Issue
Block a user