首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

排序经典有关问题1、10、11、12.19、2、20、21.29、3.怎么处理,大家应该解决过吧

2012-07-18 
排序经典问题1、10、11、12...19、2、20、21...29、3...怎么办,大家应该解决过吧?排序经典问题1、10、11、12...19、2、

排序经典问题1、10、11、12...19、2、20、21...29、3...怎么办,大家应该解决过吧?
排序经典问题1、10、11、12...19、2、20、21...29、3...怎么办,大家应该解决过吧?我是第一次面对这个问题,以前其实早该遇到,不过因为排的序列过少,没到过10.哈哈不能有mfc的qsort啊,我用的QT由于qt中中文unicode排序,我已经重载“<”实现了中文拼音排序,
class ZHLdeItem : public QStandardItem {
public:
  explicit ZHLdeItem(const QString &text) : QStandardItem(text) {}
  bool operator<( const QStandardItem & other ) const {
  std::string a(text().toAscii().data(), text().toAscii().size());
  std::string b(other.text().toAscii().data(), other.text().toAscii().size());
  return a < b;
  }
};
不过这个数字的问题不知道怎么办了。不能将1改成001神马的。求助

[解决办法]
strcmp
[解决办法]

C/C++ code
#include <stdio.h>#include <stdlib.h>static int num[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30 };int sortnum(const void *left, const void *right){  char a[10];  char b[10];  sprintf(a, "%d", *(int*)left);  sprintf(b, "%d", *(int*)right);  return strcmp(a, b);}int main(void){  int i;  int count;  count = sizeof(num) / sizeof(int);  qsort(num, count, sizeof(int), sortnum);  for (i = 0; i !+ count; ++i)    printf("%d  ", num[i]);  return 0;}}
[解决办法]
上面代码最后多打个括号,自己删掉~~

热点排行