小编use*_*696的帖子

如何从Java中的int获取最高有效的n位

我有一个int,我想获取java中的19个最高有效位。我尝试了各种方法,但没有一个起作用。有人可以帮帮我吗?

java caching bit-manipulation

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

从非空函数中释放内存

我在释放内存方面遇到了麻烦:

我得到的输出是这样的:

==11073== 1,000 bytes in 1 blocks are definitely lost in loss record 5 of 5
==11073==    at 0x4A06A2E: malloc (vg_replace_malloc.c:270)
==11073==    by 0x400B38: userInput (program.c:80)
==11073==    by 0x400DFD: playGame (program.c:150)
==11073==    by 0x4012E9: main (program.c:298)
Run Code Online (Sandbox Code Playgroud)

我使用的变量是在main之外定义的输入和答案:

char *answer;
char *input;
Run Code Online (Sandbox Code Playgroud)

我在main中使用的变量'answer'是这样的:

line 150    answer = userInput();
Run Code Online (Sandbox Code Playgroud)

功能是这样的:

char* userInput()
{
  printf ("> ");

  input = malloc (sizeof(char) * 1000); // THIS is LINE 80
  fgets(input, 1000, stdin);
  //input = realloc(input, strlen(input));

  strtok(input, "\n");

  int i = 0;
  while …
Run Code Online (Sandbox Code Playgroud)

c malloc

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

算法运行时间为O(nm ^ 2)

我想知道,因为我无法在网上找到的任何信息,是怎么样的一种算法O(n * m^2)O(n * k)O(n + k)应该进行分析?

n算数?

其他条款是多余的?

所以,O(n * m^2)实际上是O(n)

algorithm complexity-theory big-o time-complexity

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