【 数据结构(C语言)】 线性表顺序表示应用 (一)一元多项式的表示

1.稀疏多项式

【  数据结构(C语言)】 线性表顺序表示应用 (一)一元多项式的表示

#include <bits/stdc++.h>
using namespace std;
#define LIST_INIT_SIZE 25
typedef struct
{
    int *c;
    int *e;
    int length;
    int listsize;
}Sqlist;
int index;
void InitList_Sq(Sqlist &L)
{
    L.e = (int * )malloc(LIST_INIT_SIZE*sizeof(int));
    L.c = (int * )malloc(LIST_INIT_SIZE*sizeof(int));
    L.length = 0;
    L.listsize = LIST_INIT_SIZE;
}
void ListInsert_Sq(Sqlist  &L,int pos, int c,int e)
{
    L.e[pos] = e;
    L.c[pos] = c;
    L.length++;
}
int GetSum(Sqlist &L)
{
   int sum = 0;
   for (int i=0; i < L.length ; i++)
   {
       int tmp = L.c[i]*(int)pow(index,L.e[i]);
       sum += tmp;
   }
   return sum;
}
int main()
{
    Sqlist Sq;
    InitList_Sq(Sq);

    int m;
    scanf("%d",&m);

    for (int i=0; i<m; i++)
    {
        int  c,e;
        scanf("%d %d",&c,&e);
        ListInsert_Sq(Sq,i,c,e);
    }
    scanf("%d",&index);
    printf("%d
",GetSum(Sq));
    return 0;
}
/*
2
1 1
1 1
1

2
55 55
66 66
1
*/