c++/mfc/stl 中两个数组的差异函数?
Diff function on two arrays (or how to turn Old into New)
Example
One[]={2,3,4,5,6,7}
Two[]={1,2,3,5,5,5,9}
Example Result
Diff: insert 1 into One[0], One[]={1,2,3,4,5,6,7}
Diff: delete 4 from One[3], One[]={1,2,3,5,6,7}
Diff: modify 6 into 5 in One[4], One[]={1,2,3,5,5,7}
Diff: modify 7 into 5 in One[5], One[]={1,2,3,5,5,5}
Diff: append 9 into One[6], One[]={1,2,3,5,5,5,9}
Need code in c++/mfc/stl/c, Thanks.
Diff function on two arrays (or how to turn Old into New)
Example
One[]={2,3,4,5,6,7}
Two[]={1,2,3,5,5,5,9}
Example Result
Diff: insert 1 into One[0], One[]={1,2,3,4,5,6,7}
Diff: delete 4 from One[3], One[]={1,2,3,5,6,7}
Diff: modify 6 into 5 in One[4], One[]={1,2,3,5,5,7}
Diff: modify 7 into 5 in One[5], One[]={1,2,3,5,5,5}
Diff: append 9 into One[6], One[]={1,2,3,5,5,5,9}
Need code in c++/mfc/stl/c, Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要的是字符串匹配算法,通常使用动态编程实现(参见
我强烈建议使用执行差异的库,而不是自己实现。
What you need is a string matching algorithm, usually implemented using dynamic programming (see here).
I'd highly suggest using a library that performs the diff instead of implementing it yourself.
虽然通常使用字母而不是整数来完成,但计算 Levenstein 距离的常用算法在这里应该与通常应用的地方一样有效。
Though it's normally done with letters instead of integers, the usual algorithm for computing the Levenstein distance should work just as well here as where it's usually applied.
我是 C++ 差异库开发人员。
http://code.google.com/p/dtl-cpp/
使用我的 diff 库,可以计算两个序列之间的差异。
使用方法请参见examples/intdiff.cpp。
I'm diff library developer with C++.
http://code.google.com/p/dtl-cpp/
Using My diff library, it is possible to calculate the difference between two sequences.
Please see examples/intdiff.cpp about how to use.