C++ && QT 按照需求,对数据进行排序

方法一:

// 将结果按照需要的顺序输出
//******前提是第一列为纯数字  如 1 , 2.......***************//
void QtGuiApplication4::Last_result_sort(QStringList *source,QStringList *result, QStringList *sort_result)
{
	int temp;
	for (int i = 0; i < (*source).size(); i++)
	{	
		temp = (*source)[i].toDouble();
		*sort_result << (*result)[temp];
	}	
}





方法二:


// 将结果按照需要的顺序输出
//******第一列为  字母+数字   如P1 ,P2,.......  ***************//
void QtGuiApplication4::Last_result_sort_Method2(QStringList *source, QStringList *result, QStringList *sort_result)
{
	// 将P1,P2.......,P10......Pn,中的第一个字母去掉,只保留后面的数字
	QStringList number_last;
	QStringList Last_result;
	QString temp;

	for (int i = 0; i < (source[0]).size(); i++)
	{
		number_last << source[0][i].split(',');  // 分裂之后,还是以一列存放;

		for (int j = 0; j < number_last[0].size() - 1; j++)
		{

			qDebug() << "Last_result==" << number_last[0][j + 1] << endl;  //从每个字符串,第二个字符开始打印。

			temp[j] = number_last[0][j + 1]; //赋值给字符串	
		}

		Last_result.append(temp);  //压到一起

		number_last.clear();  // 必须要的清空
		temp.clear();    // 必须要的清空
	}
						 
		// 将保留的转化为数值
		double Last_result_value;
		for (int k = 0; k < Last_result.size(); k++)
		{
			Last_result_value = Last_result[k].toDouble();  //此时数值为对应下标
			qDebug() << "Last_result_value=" << Last_result_value << endl;

			// 寻找需要序列的数值
			*sort_result << (*result)[Last_result_value];   //最终输出数值
		}
	}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值