小编Eya*_*yal的帖子

数据结构模糊

我无法想象这个面试问题.

你有一个整数数组.您需要提供另一个具有以下功能的数据结构:

int get(int index)
void set (int index, int value)
void setall(int value)
Run Code Online (Sandbox Code Playgroud)

他们都做了你猜他们想做的事情.限制是每个函数都在O(1)中.

如何设计它以使setAll为O(1).

我想为每个整数添加另一个字段,这将指向每次调用setAll时都会更改的整数.当有人调用setAll然后设置然后获取时,问题就来了.

编辑:我更改了变量的名称,以便更清楚.另外,既然你问过,get假设返回array [i],设置(index,value)假设把值放在array [index]中.

setall(index, value)你应该get (get(i) == get(j) == value)为数组中的每个i,j之后.

algorithm complexity-theory

17
推荐指数
2
解决办法
2488
查看次数

C++ - 内存泄漏:指针(元)信息存储在哪里?

这是一个我无法找到答案的基本问题.

给定下一个代码,将发生内存泄漏:

   int main(){
          A* a = new A();
          // 1
     } 
     //2
Run Code Online (Sandbox Code Playgroud)

让我们说,一个获得了价值1000也就是说,在堆上地址1000现在采取的一个对象.在1,a == 1000和2 a超出范围.但缺少一些信息.

在现实生活中,地址1000是存储器中字节的地址.该字节没有存储有价值信息的信息.

我的问题:

  1. 谁保留这些信息?

  2. 这些信息是如何保存的?

  3. 哪个组件"知道"指针指向位置?计算机如何知道指向sizeof(A)字节?

谢谢!

c++ memory memory-leaks

8
推荐指数
2
解决办法
242
查看次数

Maven exec插件主类缺失

我正在尝试通过Hibernate教程并坚持运行命令

C:\Users\Eyal\workspace\FirstHibernateTutorial>mvn exec:java -Dexec.mainclass="o
rg.hsqldb.Server" -Dexec.args="-database.O file:target/data/tutorial" -e
Run Code Online (Sandbox Code Playgroud)

并得到这些错误.

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for
org.hibernate.tutorials:hibernate-tutorial:jar:1.0.0-SNAPSHOT
[WARNING] The expression ${artifactId} is deprecated. Please use ${project.artif
actId} instead.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten t
he stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support buildin
g such malformed projects.
[WARNING] …
Run Code Online (Sandbox Code Playgroud)

java hibernate maven

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

VTable和多态性

在阅读了很多关于VTables之后,我仍然有一个悬而未决的问题.

鉴于下一堂课:

#include <iostream>
using namespace std;

class Shape {
public:
    int* a;
    Shape(){
        cout<<"default Shape ctor"<<endl;
        a = new int(15); // default
    }
    Shape(int n){
        a = new int(n);
          cout<<"Shape(n) constructor"<<endl;
    }
    // copy constructor
    Shape(const Shape& s){
        cout<<"copy constructor"<<endl;
        a = new int(*(s.a));
    }
    Shape& operator=(const Shape& s){
        cout<<"operator="<<endl;

        if (&s == (this))
            return (*this);
//      this.clear();
        a = new int(*(s.a));

        return (*this);
    }


      virtual void draw(){
             cout<<"print Shape the number is "<<*a<<endl;
      };
      virtual ~Shape(){
          delete a; …
Run Code Online (Sandbox Code Playgroud)

c++ inheritance vtable

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

C++拷贝构造函数 - 小但重要的区别

我无法弄清楚这里发生了什么,认为这是非常奇怪的,并且在了解了我之后认为分享答案的原因对于某个人的时间是有价值的.

所以给出这个简单的代码:

    #include <iostream>
using namespace std;

class Shape {
public:
    int* a;
    Shape(){
        cout<<"Default Shape constructor"<<endl;
        a = new int(8); // default
    }
    Shape(int n){
        a = new int(n);
          cout<<"Shape(n) constructor"<<endl;
    }
    // copy constructor
    Shape(const Shape& s){
        cout<<"Shape copy constructor"<<endl;
        a = new int(*(s.a));
    }
    Shape& operator=(const Shape& s){
        cout<<"Shape operator="<<endl;

        if (&s == (this))
            return (*this);
//      this.clear();
        a = new int(*(s.a));

        return (*this);
    }


      virtual void draw(){
             cout<<"Print Shape the number is "<<*a<<endl;
      };
      virtual ~Shape(){ …
Run Code Online (Sandbox Code Playgroud)

c++ copy-constructor vtable

4
推荐指数
2
解决办法
1596
查看次数