我正在编写代码来解决leetcode 上的这个问题,
我解决这个问题的策略是:
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) 为什么每次循环运行时 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)