我试图通过创建一个程序来改进我的C++,该程序将需要1到10 ^ 6之间的大量数字.将在每次传递中存储数字的存储桶是一个节点数组(其中node是我创建的包含值和下一个节点属性的结构).
根据最低有效值将数字排序到桶中后,我将一个桶的末尾指向另一个桶的开头(这样我可以快速获取存储的数字而不会中断订单).我的代码没有错误(编译或运行时),但我已经找到了解决剩下的6次迭代的问题(因为我知道数字的范围).
我遇到的问题是,最初这些数字是以int数组的形式提供给radixSort函数的.在排序的第一次迭代之后,数字现在存储在结构数组中.有没有什么方法可以重新编写我的代码,以便我只有一个for循环进行7次迭代,或者我需要一个for循环,它将运行一次,而另一个循环下面将运行6次,然后返回完全排序清单?
#include <iostream>
#include <math.h>
using namespace std;
struct node
{
int value;
node *next;
};
//The 10 buckets to store the intermediary results of every sort
node *bucket[10];
//This serves as the array of pointers to the front of every linked list
node *ptr[10];
//This serves as the array of pointer to the end of every linked list
node *end[10];
node *linkedpointer;
node *item;
node *temp;
void append(int value, int n)
{
node *temp;
item=new …Run Code Online (Sandbox Code Playgroud)