用c++6.0编写程序,编译没有错误,但是运行时会显示**.exe,已停止工作,应该怎么处理

#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int key;
int num;
struct Node*next;
}Node,*Link;
void InitList(Link &L)
{
L=(Node*)malloc(sizeof(Node));
if(!L) exit(1);
L->key =0;
L->num =0;
L->next =L;
}
void Creater(int n,Link &L)
{
Link p, q;
q=L;
for(int i=1;i<=n;i++)
{
p=(Node*)malloc(sizeof(Node));
if(!p) exit(1);
printf("the key_%d is:",i);
scanf("%d",&p->key);
p->num=i;
L->next=p;
L=p;
}
L->next=q->next;
free(q);
}
void main()
{
Link L,p,q;
int n,x;
L=NULL;
InitList(L);
printf("please input the totle number of people:");
scanf("%d",&n);
printf("the start key is:");
scanf("%d",&x);
Creater(n,L);
p=L;
for(int i=1;i<-n;i++)
{
for(int j=1;j<x;j++)
p=p->next ;
q=p->next ;
x=q->key;
printf("%d",q->num );
p->next =q->next ;
free(q);
}
}

第1个回答  2019-06-17
你这点代码要完成什么功能?你连需求都不说,怎么帮你看。本回答被网友采纳