小编dag*_*ood的帖子

运行时错误:引用绑定到类型 'int' 的未对齐地址 0xbebebebebebebebec6,需要 4 字节对齐 (stl_vector.h)

我正在编写代码来解决leetcode 上的这个问题,
我解决这个问题的策略是:

  • 为每个单元格索引 (x,y) 运行 dfs
  • 在每个 dfs 调用中检查单元格是否为目标单元格
  • 相应地设置标志
  • 如果两个标志都为真,则将此单元格添加到“ans”向量中,否则继续下一个 dfs
class Solution {
public:
    void psUtil(vector<vector<int> >&mat, int x, int y, int m, int n, int &isP, int &isA, vector<vector<int> >&vis, vector<vector<int> >&ans)
    {
        //check dstinations
        if(x == 0 || y == 0)
        {
            isP = 1;
        }
        if(x == m || y == n)
        {
            isA = 1;
        }

        vector<int> cell(2);
        cell[0] = x;
        cell[1] = y;

        // check both dst rched
        if(isA …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm graph-theory depth-first-search

2
推荐指数
1
解决办法
8951
查看次数

为什么地址一样?

为什么每次循环运行时 temp 的地址(在 main 的 while 循环中)都相同我试图插入一个链表然后显示然后输出中间元素但最初在显示它时运行了一个无限循环只显示第一个元素。在插入后打印地址和 llist.add_ele_to_beg(&temp); 它每次都打印相同的地址!为什么会这样?

#include<iostream>
#include <unistd.h>

using namespace std;

class LinkedList;
class Node
{
    private:
    Node* next;
    int value;
    friend class LinkedList;
    public:
    Node(int ele) // constructor - declared in private section 
    // to prevent other classes creating objects of this class, 
    // only this class can create the object
    {
        next = nullptr;
        value = ele;
    }
};

class LinkedList
{
    private:
    Node* head;
    public:
    LinkedList()
    {
        head = nullptr;
    }
    void add_ele_to_beg(Node …
Run Code Online (Sandbox Code Playgroud)

c++ memory linked-list

1
推荐指数
1
解决办法
62
查看次数