mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-28 16:44:22 +00:00
Re-translate the Japanese version (#1871)
* Retranslate Japanese docs with GPT-5.4 * Retranslate Japanese code with GPT-5.4
This commit is contained in:
@@ -6,11 +6,11 @@
|
||||
|
||||
#include "../utils/common.hpp"
|
||||
|
||||
/* 循環配列に基づくキュークラス */
|
||||
/* 循環配列ベースのキュー */
|
||||
class ArrayQueue {
|
||||
private:
|
||||
int *nums; // キュー要素を格納する配列
|
||||
int front; // 先頭ポインタ、先頭要素を指す
|
||||
int front; // 先頭ポインタ。先頭要素を指す
|
||||
int queSize; // キューの長さ
|
||||
int queCapacity; // キューの容量
|
||||
|
||||
@@ -44,13 +44,13 @@ class ArrayQueue {
|
||||
/* エンキュー */
|
||||
void push(int num) {
|
||||
if (queSize == queCapacity) {
|
||||
cout << "Queue is full" << endl;
|
||||
cout << "キューがいっぱいです" << endl;
|
||||
return;
|
||||
}
|
||||
// 末尾ポインタを計算、末尾インデックス + 1を指す
|
||||
// 剰余演算を使用して末尾ポインタが配列の末尾から先頭に戻るようにラップ
|
||||
// 末尾ポインタを計算し、末尾インデックス + 1 を指す
|
||||
// 剰余演算により、rear が配列末尾を越えた後に先頭へ戻るようにする
|
||||
int rear = (front + queSize) % queCapacity;
|
||||
// numを末尾に追加
|
||||
// num をキュー末尾に追加
|
||||
nums[rear] = num;
|
||||
queSize++;
|
||||
}
|
||||
@@ -58,22 +58,22 @@ class ArrayQueue {
|
||||
/* デキュー */
|
||||
int pop() {
|
||||
int num = peek();
|
||||
// 先頭ポインタを1つ後ろに移動、末尾を超えた場合は配列の先頭に戻る
|
||||
// 先頭ポインタを1つ後ろへ進め、末尾を越えたら配列先頭に戻す
|
||||
front = (front + 1) % queCapacity;
|
||||
queSize--;
|
||||
return num;
|
||||
}
|
||||
|
||||
/* 先頭要素にアクセス */
|
||||
/* キュー先頭の要素にアクセス */
|
||||
int peek() {
|
||||
if (isEmpty())
|
||||
throw out_of_range("Queue is empty");
|
||||
throw out_of_range("キューが空です");
|
||||
return nums[front];
|
||||
}
|
||||
|
||||
/* 配列をVectorに変換して返却 */
|
||||
/* 配列を Vector に変換して返す */
|
||||
vector<int> toVector() {
|
||||
// 有効な長さ範囲内の要素のみを変換
|
||||
// 有効長の範囲内のリスト要素のみを変換
|
||||
vector<int> arr(queSize);
|
||||
for (int i = 0, j = front; i < queSize; i++, j++) {
|
||||
arr[i] = nums[j % queCapacity];
|
||||
@@ -82,48 +82,48 @@ class ArrayQueue {
|
||||
}
|
||||
};
|
||||
|
||||
/* ドライバーコード */
|
||||
/* Driver Code */
|
||||
int main() {
|
||||
/* キューを初期化 */
|
||||
int capacity = 10;
|
||||
ArrayQueue *queue = new ArrayQueue(capacity);
|
||||
|
||||
/* 要素エンキュー */
|
||||
/* 要素をエンキュー */
|
||||
queue->push(1);
|
||||
queue->push(3);
|
||||
queue->push(2);
|
||||
queue->push(5);
|
||||
queue->push(4);
|
||||
cout << "Queue queue = ";
|
||||
cout << "キュー queue = ";
|
||||
printVector(queue->toVector());
|
||||
|
||||
/* 先頭要素にアクセス */
|
||||
/* キュー先頭の要素にアクセス */
|
||||
int peek = queue->peek();
|
||||
cout << "Front element peek = " << peek << endl;
|
||||
cout << "先頭要素 peek = " << peek << endl;
|
||||
|
||||
/* 要素デキュー */
|
||||
/* 要素をデキュー */
|
||||
peek = queue->pop();
|
||||
cout << "Element dequeued = " << peek << ", after dequeuing";
|
||||
cout << "取り出した要素 pop = " << peek << "、取り出し後の queue = ";
|
||||
printVector(queue->toVector());
|
||||
|
||||
/* キューの長さを取得 */
|
||||
int size = queue->size();
|
||||
cout << "Length of the queue size = " << size << endl;
|
||||
cout << "キューの長さ size = " << size << endl;
|
||||
|
||||
/* キューが空かどうかを判定 */
|
||||
bool empty = queue->isEmpty();
|
||||
cout << "Is the queue empty = " << empty << endl;
|
||||
cout << "キューが空かどうか = " << empty << endl;
|
||||
|
||||
/* 循環配列をテスト */
|
||||
/* 循環配列をテストする */
|
||||
for (int i = 0; i < 10; i++) {
|
||||
queue->push(i);
|
||||
queue->pop();
|
||||
cout << "After the " << i << "th round of enqueueing + dequeuing, queue = ";
|
||||
cout << "第 " << i << " 回のエンキュー + デキュー後の queue = ";
|
||||
printVector(queue->toVector());
|
||||
}
|
||||
|
||||
// メモリを解放
|
||||
// メモリを解放する
|
||||
delete queue;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user