#include"stdio.h"
#include"stdlib.h"
typedef struct PNode
{
int coef;
int exp;
struct PNode *link;
}PNode;
typedef struct
{
struct PNode *head;
}polynominal;
void Creaete(polynominal *p)
{
PNode *pn, *pre, *q;
p->head = malloc(sizeof(PNode));
p->head->exp = -1;
p->head->link = NULL;
for (;;)
{
pn = malloc(sizeof(PNode));
printf("coef:\n");
scanf_s("%d", &pn->coef);
printf("exp:\n");
scanf_s("%d", &pn->exp);
if (pn->exp < 0) break;
pre = p->head;
q = p->head->link;
while (q&&q->exp > pn->exp)
{
pre = q;
q = q->link;
}
pn->link = q;
pre->link = pn;
}
}
void Add(polynominal *px, polynominal *qx)
{
PNode *q, *q1 = qx->head, *p, *temp;
p = px->head->link; \\编译器显示:引发了异常: 读取访问权限冲突。
q = q1->link;
while (p&&q)
{
while (p->exp < q->exp)
{
q1 = q;
q = q->link;
}
if (p->exp == q->exp)
{
q->coef = q->coef + p->coef;
if (q->coef == 0)
{
q1->link = q->link;
free(q);
q = q1->link;
p = p->link;
}
else
{
q1 = q;
q = q->link;
p = p->link;
}
}
else
{
temp = malloc(sizeof(PNode));
temp->coef = p->coef;
temp->exp = p->exp;
temp->link = q1->link;
q1->link = temp;
p = p->link;
}
}
}
void main()
{
polynominal *i, *m, *n;
Creaete(&i);
Add(&m,&n);
_getch();
}
各位大神,救救孩子吧
#include"stdlib.h"
typedef struct PNode
{
int coef;
int exp;
struct PNode *link;
}PNode;
typedef struct
{
struct PNode *head;
}polynominal;
void Creaete(polynominal *p)
{
PNode *pn, *pre, *q;
p->head = malloc(sizeof(PNode));
p->head->exp = -1;
p->head->link = NULL;
for (;;)
{
pn = malloc(sizeof(PNode));
printf("coef:\n");
scanf_s("%d", &pn->coef);
printf("exp:\n");
scanf_s("%d", &pn->exp);
if (pn->exp < 0) break;
pre = p->head;
q = p->head->link;
while (q&&q->exp > pn->exp)
{
pre = q;
q = q->link;
}
pn->link = q;
pre->link = pn;
}
}
void Add(polynominal *px, polynominal *qx)
{
PNode *q, *q1 = qx->head, *p, *temp;
p = px->head->link; \\编译器显示:引发了异常: 读取访问权限冲突。
q = q1->link;
while (p&&q)
{
while (p->exp < q->exp)
{
q1 = q;
q = q->link;
}
if (p->exp == q->exp)
{
q->coef = q->coef + p->coef;
if (q->coef == 0)
{
q1->link = q->link;
free(q);
q = q1->link;
p = p->link;
}
else
{
q1 = q;
q = q->link;
p = p->link;
}
}
else
{
temp = malloc(sizeof(PNode));
temp->coef = p->coef;
temp->exp = p->exp;
temp->link = q1->link;
q1->link = temp;
p = p->link;
}
}
}
void main()
{
polynominal *i, *m, *n;
Creaete(&i);
Add(&m,&n);
_getch();
}
各位大神,救救孩子吧