小编Jer*_*fin的帖子

整数溢出问题

我不断得到一个整数溢出问题,我不知道如何解决它可以有人帮忙吗?edx conatins 181和eax包含174

       xor eax,edx       
       mov edx,2
       div edx   
Run Code Online (Sandbox Code Playgroud)

x86 assembly

7
推荐指数
2
解决办法
8393
查看次数

链接列表反向没有临时

有没有办法在不使用C中的临时变量的情况下反转链表?提前致谢.

着名的方法:

Element *reverse(Element *head)
{
    Element *previous = NULL;

    while (head != NULL) {
        // Keep next node since we trash
        // the next pointer.
        Element *next = head->next;

        // Switch the next pointer
        // to point backwards.
        head->next = previous;

        // Move both pointers forward.
        previous = head;
        head = next;
    }

    return previous;
}
Run Code Online (Sandbox Code Playgroud)

使用临时变量

SAURABH

c linked-list data-structures

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

算法效率

所以这是我作业中的一个问题....

假设算法的效率为n 3,如果算法中的步长需要1 ns(10 -9)秒,那么算法处理大小为1,000的输入需要多长时间?

这是我的问题:我如何解决这个问题?请不要发布答案.帮助我学习如何为自己解决这个问题.

algorithm performance

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

搜索文件中的字符串,并将匹配的行写入Java中的另一个文件

为了在文件中搜索字符串并将匹配字符串的行写入另一个文件,对于70MB(压缩状态)的单个zip文件,需要15-20分钟.有没有办法减少它.

我的源代码:

获取Zip文件条目

zipFile = new ZipFile(source_file_name);

entries = zipFile.entries();

while (entries.hasMoreElements())

{ ZipEntry entry = (ZipEntry)entries.nextElement();

if (entry.isDirectory()) 
{ 
continue; 
} 
searchString(Thread.currentThread(),entry.getName(), new BufferedInputStream (zipFile.getInputStream(entry)), Out_File, search_string, stats); }

zipFile.close();
Run Code Online (Sandbox Code Playgroud)

搜索字符串

public void searchString(Thread CThread, String Source_File, BufferedInputStream in, File outfile, String search, String stats) throws IOException

{ 

    int count = 0; 
    int countw = 0; 
    int countl = 0; 
    String s; 
    String[] str; 
    BufferedReader br2 = new BufferedReader(new InputStreamReader(in)); 
    System.out.println(CThread.currentThread()); 

        while ((s = br2.readLine()) != null) 
        { 
            str …
Run Code Online (Sandbox Code Playgroud)

java file-io

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

使用位移找到整数平方根的最快方法是什么?

我一直在寻找计算数字(整数)的平方根(整数)的最快方法.我在维基百科中遇到了这个解决方案,它找到了一个数字的平方根(如果它是一个完美的正方形)或者它最近的下方完美正方形的平方根(如果给定的数字不是一个完美的正方形:

short isqrt(short num) {
    short res = 0;
    short bit = 1 << 14; // The second-to-top bit is set: 1L<<30 for long
    // "bit" starts at the highest power of four <= the argument.
    while (bit > num)
        bit >>= 2;
    while (bit != 0) {
        if (num >= res + bit) {
            num -= res + bit;
            res = (res >> 1) + bit;
        }
        else
            res >>= 1;
        bit >>= 2;
    }
    return res;
}
Run Code Online (Sandbox Code Playgroud)

我尝试了很多测试运行来跟踪算法,但我似乎并不理解里面的部分 …

bit-shift square-root memory-efficient

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

通过初始化列表调用另一个类的构造函数.有问题

这是我的示例代码:

#include <iostream>
using namespace std;

class Base
{
public:
    Base (int v, char z) {x=v;y=z;};
    int x;
    char y;
};

class Bar
{
public:
    Bar(int m, char n):q(m),s(n),base(q,s){};
    Base base;
    int q;
    char s;    
};

int main()
{
    Bar barObj(5,'h');    
    cout << barObj.base.x << barObj.base.y << endl;       
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么我得到了输出0http://ideone.com/pf47j

此外,在一般情况下,什么是创造另一个类的成员对象,并调用该对象的构造正确的方法,如上面做用的对象库class Base,里面class Bar

c++ constructor class object initializer-list

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

BST输入的可能排列

给我一个字符串,即"CPHBDZ".通过(按此顺序)将字母插入BST,我将:

  C
 / \
B   P
   / \
  H   Z
 /
D
Run Code Online (Sandbox Code Playgroud)

如果我们将字符串的顺序更改为"CBPHDZ",我们将得到相同的树.我必须找到并列出提供相同BST的输入字符串的所有排列.我想出了如何计算这些排列的数量,但我无法弄清楚实际找到它们的任何算法.

language-agnostic algorithm permutation binary-search-tree

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

解析器实现

嗨,我正在尝试用这样的语法实现一个简单语言的解析器.

program ::= "program" declarations "begin" statements "end"
declaration ::= "var" ident "as" type
type ::= "string" | "int"
Run Code Online (Sandbox Code Playgroud)

我完成了前两个,我怎么写类型语法?

program( prog( DECLS, STATS ) ) -->
[ 'program' ], declarations( DECLS ),
[ 'begin' ], statements( STATS ), [ 'end' ].

declaration( decl( IDENT, TYPE ) ) -->
[ 'var' ], ident( IDENT ), [ 'as' ], type( TYPE ).
Run Code Online (Sandbox Code Playgroud)

parsing prolog

5
推荐指数
0
解决办法
209
查看次数

C#Interop Excel格式,如Excel的格式为表格

我导出表从SQLiteExcel中(2010年)C#.它工作正常.我正在使用这种Excel.Range.set_Value()方法.

如何格式化Excel.Range类似Excel's格式(如表格)?

c# formatting excel-interop

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

DirectoryInfo.GetFiles,如何在C#中获取不同类型的文件

如何使用DirectoryInfo.GetFilesC#中的函数找到文件类型*.gif和*.jpg ?

当我尝试这段代码时:

string pattern = "*.gif|*.jpg";
FileInfo[] files = dir.GetFiles(pattern);
Run Code Online (Sandbox Code Playgroud)

例外"路径中的非法字符".被扔了.

c# directory search file filter

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