devc++测试排序算法的时候 输入数据量超过1000个,程序就没有结果(附代码)?
#include"stdio.h"#include"stdlib.h"#include"time.h"typedefstructNode{intdata;structNo...
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
typedef struct Node
{
int data;
struct Node *next;
}LNode, *LinkList;
void create_list(LinkList *L);//创建链表
void traverse_list(LinkList pHead);//遍历链表
bool is_empty(LinkList pHead);//判断链表是否为空
int length_list(LinkList);//返回链表的元素个数
/*
//单链表插入排序算法
*/
void insert_sort_list(LinkList L);
void insert_sort_list(LinkList *L)
{
LinkList first;
LinkList t;
LinkList p;
LinkList q;
LinkList head;
/*
将链表拆为有序元素组成的链表和无序元素组成的链表
*/
head= (*L)->next;
first = head->next;
head->next = NULL;
while (first != NULL) {
for (t = first, q = head; ((q != NULL) && (q->data < t->data)); p = q, q = q->next);
first = first->next;
if (q == head)
{
(*L)->next = t;
t->next = head;
head = (*L)->next;
}
else
{
p->next = t;
t->next = q;
}
};
}
void traverse_list(LinkList L) {
LinkList p = L->next;
while(NULL != p) {
printf("%d ", p->data);
p = p->next;
}
printf("\n");
return;
}
void create_list(LinkList *L) {
int i;
int n;
int val;
*L = (LinkList)malloc(sizeof(LNode));
LinkList pTail = *L;
pTail->data = 0;
pTail->next = NULL;
printf("请输入您需要生成的结点个数:");
scanf("%d", &n);
printf("输入数据\n");
for(i = 0; i < n; i++) {
scanf("%d", &val);
LinkList pNew = (LinkList)malloc(sizeof(LNode));
pNew->data = val;
pNew->next = NULL;
pTail->next = pNew;
pTail = pNew;
}
}
main() {
LinkList La = NULL;
clock_t start, finish;
double duration;
create_list(&La);
printf("排序前元素:");
traverse_list(La);
start=clock();
insert_sort_list(&La);
finish=clock();
printf("排序后元素:");
traverse_list(La);
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%f seconds\n", duration );
return 0;
} 展开
#include "stdlib.h"
#include "time.h"
typedef struct Node
{
int data;
struct Node *next;
}LNode, *LinkList;
void create_list(LinkList *L);//创建链表
void traverse_list(LinkList pHead);//遍历链表
bool is_empty(LinkList pHead);//判断链表是否为空
int length_list(LinkList);//返回链表的元素个数
/*
//单链表插入排序算法
*/
void insert_sort_list(LinkList L);
void insert_sort_list(LinkList *L)
{
LinkList first;
LinkList t;
LinkList p;
LinkList q;
LinkList head;
/*
将链表拆为有序元素组成的链表和无序元素组成的链表
*/
head= (*L)->next;
first = head->next;
head->next = NULL;
while (first != NULL) {
for (t = first, q = head; ((q != NULL) && (q->data < t->data)); p = q, q = q->next);
first = first->next;
if (q == head)
{
(*L)->next = t;
t->next = head;
head = (*L)->next;
}
else
{
p->next = t;
t->next = q;
}
};
}
void traverse_list(LinkList L) {
LinkList p = L->next;
while(NULL != p) {
printf("%d ", p->data);
p = p->next;
}
printf("\n");
return;
}
void create_list(LinkList *L) {
int i;
int n;
int val;
*L = (LinkList)malloc(sizeof(LNode));
LinkList pTail = *L;
pTail->data = 0;
pTail->next = NULL;
printf("请输入您需要生成的结点个数:");
scanf("%d", &n);
printf("输入数据\n");
for(i = 0; i < n; i++) {
scanf("%d", &val);
LinkList pNew = (LinkList)malloc(sizeof(LNode));
pNew->data = val;
pNew->next = NULL;
pTail->next = pNew;
pTail = pNew;
}
}
main() {
LinkList La = NULL;
clock_t start, finish;
double duration;
create_list(&La);
printf("排序前元素:");
traverse_list(La);
start=clock();
insert_sort_list(&La);
finish=clock();
printf("排序后元素:");
traverse_list(La);
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%f seconds\n", duration );
return 0;
} 展开
1个回答
2020-04-09
展开全部
输入数据量超过1000个??
我的 天,还不如 随机函数生成
int main()
{ int i=0,t;
srand((unsigned)time(NULL));
t=rand() % 1000;
intRandom[i++]=t;
while (i<100)
{
Again: t=rand() % 1000;
if ( BoolInArray(t,i)==0)
{ intRandom[i++]=t; }
else
goto Again; }
for(i=0;i<100;i++)
{ printf("%4d",intRandom[i]);
if ((i+1) % 10 == 0)
printf("\n");
}
return 0;
我的 天,还不如 随机函数生成
int main()
{ int i=0,t;
srand((unsigned)time(NULL));
t=rand() % 1000;
intRandom[i++]=t;
while (i<100)
{
Again: t=rand() % 1000;
if ( BoolInArray(t,i)==0)
{ intRandom[i++]=t; }
else
goto Again; }
for(i=0;i<100;i++)
{ printf("%4d",intRandom[i]);
if ((i+1) % 10 == 0)
printf("\n");
}
return 0;
追问
就是我的dvc写存储结构的时候,存储数据超过大约1000个的时候,就没法生成序列,不管是链式的还是顺序的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询