请帮我找出程序错误的地方#includeusing namespace std;#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0typedef char ElemType;typedef int Status;typedef struct LNode{ElemType data;struct LNode *next;}LNode,*LinkList;void CreatList_L(L
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/27 22:08:14
请帮我找出程序错误的地方#includeusing namespace std;#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0typedef char ElemType;typedef int Status;typedef struct LNode{ElemType data;struct LNode *next;}LNode,*LinkList;void CreatList_L(L
请帮我找出程序错误的地方
#include
using namespace std;
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
typedef char ElemType;
typedef int Status;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
void CreatList_L(LinkList &L,int n)//头插法创立单链表
{
int i;
LinkList p,q;
L=(LinkList)malloc(sizeof(LNode));
q=L;
coutnext=r->next;
r->next=q;
r=r->next;
}
else
if((q->data>= '0') && (q->datanext;
q->next=s->next;
s->next=q;
s=s->next;
}
else
{
q=p;
p=p->next;
q->next=r->next;
t->next=q;
t=t->next;
}
}
q=L;
free(q);
return OK;
}
void main()
{
LinkList L,L1,L2,L3;
int n;
coutn;
CreatList_L(L,n);
OutputList_L(L);
fenlei(L,L1,L2,L3);
OutputList_L(L1);
OutputList_L(L2);
OutputList_L(L3);
}
请帮我找出程序错误的地方#includeusing namespace std;#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0typedef char ElemType;typedef int Status;typedef struct LNode{ElemType data;struct LNode *next;}LNode,*LinkList;void CreatList_L(L
错误主要是粗心造成的,就 fenlei函数 有问题,请对比
Status fenlei(LinkList &L,LinkList &L1,LinkList &L2,LinkList &L3)
{
LinkList p,q,r,s,t;
L1=(LinkList)malloc(sizeof(LNode));
L2=(LinkList)malloc(sizeof(LNode));
L3=(LinkList)malloc(sizeof(LNode));
L1->next = NULL;
L2->next = NULL;
L3->next = NULL;
p=L->next;
r=L1;s=L2;t=L3;
while(p!=NULL)
{
if((p->data>='A'&&p->data<='Z')||(p->data>='a'&&p->data<='z'))
{
q=p;
p=p->next;
q->next=r->next;
r->next=q;
r=r->next;
}
else if((p->data>= '0') && (p->data<= '9'))
{
q=p;
p=p->next;
q->next=s->next;
s->next=q;
s=s->next;
}
else
{
q=p;
p=p->next;
q->next=t->next;
t->next=q;
t=t->next;
}
}
q=L;
free(q);
return OK;
}