# C++基数排序问题

0

#include<iostream>
#include<string>
#include<malloc.h>
using namespace std;

#define maxr 10
#define maxd 8
{
{
char data[maxd];
}RecType;
RecType *p;
public:
};

{
while (r.p != NULL)
{
cout << r.p->data << " ";
r.p = r.p->next;
}
cout << endl;
}
{
int i, j, k;
for (i = d - 1; i >= 0; i--)
{
for (j = 0; j < r; j++)
while (p != NULL)
{
k = p->data[i] - '0';
{
tail[k] = p;
}
else
{
tail[k]->next = p;
tail[k] = p;
}
p = p->next;
}
p = NULL;
for (j = 0; j < r; j++)
{
if (p == NULL)
{
t = tail[j];
}
else
{
t = tail[j];
}
}
//t->next = NULL;
cout << "order by " << d - i - 1 << " bit ";
}
}

{
int i;
RecType *s, *t = NULL;
for (i = 0; i < n; i++)
{
s = (RecType*)malloc(sizeof(RecType));
strcpy_s(s->data, a[i]);
if (i == 0)
{
p = s;
t = s;
}
else
{
t->next = s;
t = s;
}
}
t->next = NULL;
}
void main()
{

char *a[10] = { "23", "24", "32", "56", "67", "45", "87", "98", "48", "65" };
}

0
```// Radix.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include<iostream>
#include<string>
#include<malloc.h>
using namespace std;

#define maxr 10
#define maxd 8

{
char data[maxd];
}RecType;

{
RecType *p;
public:
};

{
//而直接使用r.p，破坏了原有数据，应该使用临时变量指针保留r的现场
RecType *t = r.p;
while (t != NULL)
{
cout << t->data << " ";
t = t->next;
}
cout << endl;
}
{
int i, j, k;
for (i = d - 1; i >= 0; i--)
{
for (j = 0; j < r; j++)
while (p != NULL)
{
k = p->data[i] - '0';
{
tail[k] = p;
}
else
{
tail[k]->next = p;
tail[k] = p;
}
p = p->next;
}
p = NULL;
for (j = 0; j < r; j++)
{
{
if (p == NULL)
{
t = tail[j];
}
else
{
t = tail[j];
}
}
}
t->next = NULL;//缺少该语句，导致死循环
cout << "order by " << d - i - 1 << " bit ";
}
}

{
int i;
RecType *s, *t = NULL;
for (i = 0; i < n; i++)
{
s = (RecType*)malloc(sizeof(RecType));
strcpy_s(s->data, a[i]);
if (i == 0)
{
p = s;
t = s;
}
else
{
t->next = s;
t = s;
}
}
t->next = NULL;
}

void main()
{
char *a[10] = { "23", "24", "32", "56", "67", "45", "87", "98", "48", "65" };
}```

519740105 | 大侠五级 |园豆：5810 | 2014-09-04 07:17

您需要登录以后才能回答，未注册用户请先注册