求帮忙改下C语言代码,要求是用线性表实现两个多项式相乘。代码这里写不完了,看截图,有什么不清楚问我
这个是母函数的知识,这一块我没怎么看,楼主可以自己百度一下。大概的意思就是: a[x]:x表示指数,a[x]存系数。如 3x^2+4x+5:可表示为:a[2]=3,a[1]=4,a[0]=5. 多项式加减就是a[x]相加减。多项式相乘就是x相加。也就是下标的运算
#include #include #include #include using namespace std;unsigned int test_array[] ={ 1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20, 21,22,23,24,25,26,27,28,29,30, 31,32,33,34,35,36,37,38,39,40, 41,42,43,44,45,46,47,48,49,50, 51,52,53,54,55,56,57,58,59,60, 61,62,63,64,65,66,67,68,69,70, 71,72,73,74,75,76,77,78,79,80, 81,82,83,84,85,86,87,88,89,90, 91,92,93,94,95,96,97,98,99,100};/*+,-,*,/,(,),@,#*/char cmp_table[][8] ={ {'>','>','',''}, {'>','>','',''}, {'>','>','>','>','',''}, {'>','>','>','>','',''}, {'','>','>','>','$','>',''}, {'>','>','>','>',''}, {'_operator != 0) { printf("%c ",start->_operator); } else printf("%d ",start->operand); start = start->next; } printf("
");}void showarray(UNIT *start,int pStart){ int i; for(i=0;i') { LinearTable[pLinearTable++]._operator = Stack[--pStack]._operator; } if(cmp_operator(Stack[pStack-1]._operator,unit[i]._operator) == '=') { if(Stack[pStack-1]._operator == '(' && unit[i]._operator == ')') { pStack--; if(pStack >0 && Stack[pStack-1]._operator == '@') { LinearTable[pLinearTable++]._operator = Stack[--pStack]._operator; } } } if(cmp_operator(Stack[pStack-1]._operator,unit[i]._operator) == 'next != NULL) { //printf("%d %d %c
",operand_1->operand,operand_2->operand,pOperator->_operator); //printf("calc:
"); //showlink(LinearTable,0); if(LinearTable[0].next->_operator == '@') { printf("is in @
"); operand_2 = &LinearTable[0]; pOperator = LinearTable[0].next; } else if(LinearTable[0].next->next != NULL) { operand_2 = LinearTable[0].next; pOperator = LinearTable[0].next->next; } else is_valid = false; while(pOperator != NULL && pOperator->_operator == 0) { operand_1 = operand_1->next; operand_2 = operand_2->next; pOperator = pOperator->next; } //showlink(LinearTable,0); switch(pOperator->_operator) { case '@': operand_2->operand = *((unsigned int *)(operand_2->operand)); operand_2->next = pOperator->next; showlink(LinearTable,0); break; case '+': operand_1->operand = operand_1->operand + operand_2->operand; operand_1->next = pOperator->next; break; case '-': operand_1->operand = operand_1->operand - operand_2->operand; operand_1->next = pOperator->next; break; case '*': operand_1->operand = operand_1->operand * operand_2->operand; operand_1->next = pOperator->next; break; case '/': operand_1->operand = operand_1->operand / operand_2->operand; operand_1->next = pOperator->next; break; } operand_1 = &LinearTable[0]; } if(is_valid) result = operand_1->operand; else result = -1; free(LinearTable); free(Stack); free(unit); return result;}操作示例:
scanf("%d",&s->data);
scanf("%d",&s->expn);
要改成
scanf("%d^%d",&s->data,&s->expn);
int main()函数中的
headC=multiply(&A, &B, &C);
要改成
headC=multiply(headA, headB, &C);
已知线性表LA和LB中的数据元素按值非递减有序排列,现要求将LA和LB归并为一个新的线性表LC,且LC中的数据元素仍按值非递减有序排列。例如,设LA=(3,5,8,11);LB=(2,6,8,9,11,15,20),则LC=(2,3,5,6,8,8,9,11,11,15,20)。(求代码,不是算法,还有就是
求大神帮忙用C语言写一个程序。 要求:定义两个线性表(内容由用户输入...
include <stdlib.h> include<string.h> include <stdbool.h> typedef struct{ int *data;int length; \/\/ 线性表的长度 int top; \/\/ 线性表的当前元素个数 }List;\/\/ 初始化线性表 void list_init(List *li,int length){ li->length = length;li->top = 0;li->data = (int*) ...
用c语言编程求线性方程组的解
} 徐世良老师的.原地工作全选主元的高斯消元.用的符号有点诡异,而且将矩阵以线性表输入的.我也写过一个,不过估计你不太喜欢用我的,这个用来解b也是矩阵的.include <stdio.h> include <stdlib.h> include <math.h> void swap(double *a,double *b){ double temp;temp=*a;a=*b;b=temp;} ...
谁能帮我设计一个C语言程序,求解方程组的,急啊,哪位高手帮下咯,万分感...
假定你要的是线性方程组,下面的 float *GauseSeidel(float *a,int n)是高斯赛德尔法求解线性方程组的通用子程序。N 是 迭代次数极限。main()里写了调用的例子。include <stdio.h> include <stdlib.h> include <math.h> define N 100 float *GauseSeidel(float *a,int n){ int i,j,nu=0;...
C语言程序设计:线性方程组求解
程序能成功运行,用的高斯消元法 不过没有给出菜单 输入提示信息比较清楚 某次的结果如下:你要解几元线性方程组:2 请输入第1行相应的系数:a[0][0]: 2 a[0][1]: -1 请输入第1行相应的常数:b[0]: 3 请输入第2行相应的系数:a[1][0]: 1 a[1][1]: 1 请输入第2行相应的常...
【100分】数据结构——使用C语言(线性表)
{\/\/构造一个空线性表L La.elem=(int *) malloc(100 *sizeof(int));\/\/分配空间 if (!La.elem) exit(-2);\/\/未分配则 跳出;La.length=0;La.listsize= 100 ;} int Listinsert_sq(sqlist &L,int i,int e) \/\/ listinsert_sq;插入一个元素 {int *newbase;int *p,*q;if (i<...
怎么用C语言实现最小二乘法?
最小二乘法常用于根据实测数据求线性方程的最近似解。根据如图(图片引用于百度百科)的描述,利用C语言求,使用最小二乘法算法求线性方程的解,程序如下:include <stdio.h>#define N 4 \/\/共有4个记录,根据需要增加记录typedef struct Data{ \/\/定义实验记录结构 int w; \/\/实验次数 double x; ...
用C语言编写线性表的逆置的程序.
struct list *head){ \/\/用于链表的逆转 struct list *p=NULL,*q;while(head!=NULL){ q=p;p=head;head=head->next;p->next=q;} head=p;return head;} main(){ struct list *head;head=CreateList(5);head=Inverse(head);Output(head);getch();} 希望我的回答对你有帮助!
线性表的基本操作c语言实现
代码如下:头文件:2_1.h ifndef _2_1_H define _2_1_H typedef void SeqList;typedef void SeqListNode;\/\/创建线性表 SeqList * SeqList_Create(int capacity);\/\/销毁线性表 void SeqList_DesTroy(SeqList * list);void SeqList_Clear(SeqList* list);int SeqList_Length(SeqList* ...
请使用C语言代码,分别用crout分解法和Gauss-Seidel迭代法,求解线性方 ...
include<cmath> using namespace std;define N 3 long double a[N][N];long double b[N];long double eps;long double x[N]; \/\/声明系数矩阵,方程右侧值,相对误差分析,解的初始值 void GetData(); \/\/获得数据 void Gauss_Seidel(); \/\/高斯迭代 void Show(); \/\/输出结果...
用C语言编写链式存储结构下实现线性表的创建,插入,删除,按值查找
int data;\/\/链表数据 struct LNode* next;\/\/链表指针 }LNode,*LinkList;\/*头插法-建立单链表*\/ LinkList HeadCreate(LinkList la){ int num;la=(LinkList)malloc(sizeof(LNode));\/\/建立头结点 la->next=NULL;scanf("%d",&num);while(num!=10){ LNode *p=(LinkList)malloc(sizeof(...