通过C语言调用函数的方式来实现线性表的基本操作.doc_第1页
通过C语言调用函数的方式来实现线性表的基本操作.doc_第2页
通过C语言调用函数的方式来实现线性表的基本操作.doc_第3页
通过C语言调用函数的方式来实现线性表的基本操作.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验项目一请通过C语言调用函数的方式来实现线性表的基本操作:1. 创建、初始化 线性表2. 事先给定e, 返回其位序3. 事先给定e,删除e4. 有序表中, 插入e5. 销毁线性表 二(1)用带头结点的单链表表示多项式,表中每一个结点表示多项式中的一项 ;(2) 一元多项式简单计算器的基本功能为: 输入并建立多项式;输出多项式;两个多项式相减。(多项式的各项以指数形式输出)所属课程算法与数据结构实验目的通过本实验,基本掌握线性表的逻辑结构、存储结构及其建立、插入、删除等基本操作。通过相关算法的C语言实现,并考虑线性表在多项式运算中的应用。实验内容(一)请通过C语言调用函数的方式来实现线性表的基本操作:1. 创建、初始化 线性表2. 事先给定e, 返回其位序3. 事先给定e,删除e4. 有序表中, 插入e5. 销毁线性表 注意:通过适当的例子加以调试说明。 (二)设计一个一元多项式简单的计算器。要求: (1)用带头结点的单链表表示多项式,表中每 一个结点表示多项式中的一项 ;(2) 一元多项式简单计算器的基本功能为: 输入并建立多项式;输出多项式;两个多项式相减。(多项式的各项以指数形式输出)实验过程及结果#include#include#define List_Init_Size 100#define Listincrement 10#define OVERFLOW 0#define OK 1#define ERROR 0typedef int ElemType;typedef int status;typedef struct ElemType *elem; int length; int listlize; sqList;status InitList(sqList *L)L-elem=(ElemType*)malloc(List_Init_Size*sizeof(ElemType); if(!L-elem)exit(OVERFLOW); L-length=0; L-listlize=List_Init_Size; return OK;status LocateElemList(sqList *L,ElemType e) int i=0; while(ilength&(L-elemi!=e)+i; if(ilength) return i+1; else return 0; status DeleteList(sqList *L,ElemType i) ElemType e; ElemType *p,*q; if(iL-length)return ERROR; p=&(L-elemi-1); e=*p; q=L-elem+L-length-1; for(+p;plength; return e;status InsertList(sqList *L,int i,ElemType e) ElemType *p,*q; if(iL-length)return ERROR; if(L-length=L-listlize) L-elem=(ElemType*)realloc(L-elem,(L-listlize+ Listincrement)*sizeof(ElemType); if(!L-elem)exit(OVERFLOW); L-listlize+=Listincrement; q=&(L-elemi-1); for(p=&L-elemL-length-1;p=q;-p); *(p+1)=*p; *q=e; +L-length; return OK; status DestoryList(sqList *L) free(L); return OK;void main() int i,l,e; sqList a; InitList(&a); printf(Please input array 5 number:); for(i=0;i5;i+) scanf(%d,&a.elemi); a.length=i;printf(please input a number to be located:);scanf(%d,&e);l=LocateElemList(&a,e);if(l=0)printf(the element %d does not in the list.n,e);else printf(the element %d is the %dth in the listn,e,l);printf(Input the Insert data:); scanf(%d,&e); printf(Input the Insert locate:); scanf(%d,&i); if(InsertList(&a,i,e) printf(output the datas:); for(i=0;i5;i+) printf(%d ,a.elemi); else printf(Cant insert the data!); printf(nInput the delete element:); scanf(%d,&i);if(DeleteList( &a,e) printf(delete succeed!n); else printf(Cant find the delete data!n); DestoryList(&a); getch();#include typedef struct polynode int coef; int exp; struct polynode *next; node; node *create() node *h,*r,*s; int c,e; h=(node*)malloc(sizeof(node); r=h; printf(coef:); scanf(%d,&c); printf(exp: ); scanf(%d,&e); while(c!=0) s=(node*)malloc(sizeof(node); s-coef=c; s-exp=e; r-next=s; r=s; printf(coef:); scanf(%d,&c); printf(exp: ); scanf(%d,&e); r-next=NULL; return(h); void print(node *p) while(p-next!=NULL) p=p-next; printf( %d*x%d,p-coef,p-exp); void polyadd(node *ha, node *hb) node *p,*q,*pre,*temp; int sum; p=ha-next; q=hb-next; pre=ha; while(p!=NULL&q!=NULL) if(p-expexp) pre-next=p; pre=pre-next; p=p-next; else if(p-exp=q-exp) sum=p-coef-q-coef; if(sum!=0) p-coef=sum; pre-next=p;pre=pre-next;p=p-next; temp=q;q=q-next;free(temp); else temp=p-next;free(p);p=temp; temp=q-next;free(q);q=temp; else pre-next=q; pre=pre-next; q=q-next; if(p!=NULL) pre-next=p; else pre-next=q; void multipoly(node *ha,node *hb) node *p,*q,*n,*m; p=ha-next; n=(node*)malloc(sizeof(node); n-next=NULL; while(p!=NULL) m=(node*)malloc(sizeof(node); for(q=hb-next;q;q=q-next) m-coef=p-coef*q-coef; m-exp=p-exp+q-exp; m-next=NULL; p=p-next; polyadd(n,m); print(n); void main() node *ha,*hb; printf(input ha de xishu zhishu :n); ha=create(); p

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论