[求助]我的程序编译怎么出现了乱码!
这是一个一元多项式的程序,编译是通过了,可是指数却出现了乱码,请各位高手帮帮忙看一下是怎么回事!#include <iostream>
using namespace std;
typedef struct node
{
float coef;
int expn;
struct node *next;
}PolyNode;
void InitList(PolyNode *&sq)
{
sq=(PolyNode*)malloc(sizeof(PolyNode));
sq->next=NULL;
}
int GetLength(PolyNode *sq){
int i=0;
PolyNode *p=sq->next;
while (p!=NULL)
{
i++;p=p->next;
}
return i;
}
PolyNode *GetElem(PolyNode *sq,int i)
{
int j=1;
PolyNode *p=sq->next;
if(i<1||i>GetLength(sq))
return NULL;
while (j<i){
p=p->next;j++;
}
return p;
}
PolyNode *Locate(PolyNode *sq,float c,int e)
{
PolyNode *p=sq->next;
while(p!=NULL&&(p->coef!=c||p->expn!=e))
p=p->next;
return p;
}
int OrderInsElem(PolyNode *sq,float c,int e,int i)
{
int j=1;
PolyNode *p=sq,*s;
s=(PolyNode *)malloc(sizeof(PolyNode));
s->coef=c;s->expn=e; s->next=NULL;
if(i<1||i>GetLength(sq)+1)
return 0;
while (j<i){
p=p->next;j++;
}
s->next=p->next;
p->next=s;
return 1;
}
int DelElem(PolyNode *sq,int i){
int j=1;
PolyNode *p=sq,*q;
if(i<1||i>GetLength(sq))
return 0;
while (j<i){
p=p->next;j++;
}
q=p->next;
p->next=q->next;
free(q);
return 1;
}
void DispList(PolyNode *sq)
{
PolyNode *p=sq->next;
while (p!=NULL){
cout<<"("<<p->coef<<','<<p->next<<")";
p=p->next;
}
cout<<endl;
}
void CreatPolyList(PolyNode *&sq,float C[], int E[],int n){
int i;
InitList(sq);
for(i=0;i<n;i++)
OrderInsElem(sq,C[i],E[i],i+1);
}
void SortPoly(PolyNode *&sq){
PolyNode *p=sq->next,*q,*pre;
sq->next=NULL;
while(p!=NULL){
if (sq->next==NULL)
{
sq->next=p;p=p->next;
sq->next->next=NULL;}
else{
pre=sq;q=pre->next;
while(q!=NULL&&p->expn>q->expn){
pre=q;q=q->next;}
q=p->next;
p->next=pre->next=p;
p=q;
}}}
void main(){
PolyNode *sq1;
float C1[]={1,2,3,4};
int E1[]={0,0,0,0};
CreatPolyList(sq1,C1,E1,4);
cout<<"多项式A为:";DispList(sq1);SortPoly(sq1);
}