用地址而不是数字填充队列
Fill a queue with address instead of numbers
我想知道您是否可以将地址而不是其内容推送到队列中。例如,我有一个 2D 数组,我正在它周围移动。我想跟踪我去过的地方,我不一定关心这些景点的内容。
是的,您只需要将队列声明为指针队列,例如" int*"或您使用的任何类型。代码如下:
#include <iostream>
#include <queue>
using namespace std;
int main() { ios_base::sync_with_stdio(0);
int a = 3, b = 4, c = 25;
queue <int*> q;
q.push(&a);
q.push(&b);
q.push(&c);
while (!q.empty()) {
cout << *q.front() << "->"; // printing values
cout << q.front() << ' '; // printing adresses
q.pop();
}
cout << 'n';
return 0;
}
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 检查输入是否不是整数或数字
- 在c++中用vector填充一个简单的动态数组
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- 如何使用用户输入在C++中正确填充2D数组
- 将数字转换为填充字符串
- 用C++中的数字和条件填充向量
- C++以特定方式用数字填充矩阵
- 如何从逗号分隔的数字对中填充 2 个向量 C++.
- Qt究竟是如何处理字符串的,或者如何生成填充数字
- 用地址而不是数字填充队列
- 我需要在部分填充的数组中找到最大的数字
- 声明一个类型为String的数组,该数组包含带填充的数字
- 如果我有一个固定大小的填充ascii数字的char数组,我知道它指的是一个无符号整数,那么将其转换为无符号整数的最快方法
- 填充列表<>使用数组获取错误的数字
- 使用 std::fill 用递增的数字填充矢量
- 如何将填充零添加到写入流的数字中
- 使用函数填充数组中的数字.如果数组已满,则该数字将在第二个数组中填充
- 使用循环将数字填充矩阵A (Eigen::Matrix2d A)