通过C语言调用函数的方式来实现线性表的基本操作.doc

上传人:sk****8 文档编号:3124942 上传时间:2019-05-22 格式:DOC 页数:4 大小:108.50KB
下载 相关 举报
通过C语言调用函数的方式来实现线性表的基本操作.doc_第1页
第1页 / 共4页
通过C语言调用函数的方式来实现线性表的基本操作.doc_第2页
第2页 / 共4页
通过C语言调用函数的方式来实现线性表的基本操作.doc_第3页
第3页 / 共4页
通过C语言调用函数的方式来实现线性表的基本操作.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

1、实验项目一请通过 C语言调用函数的方式来实现线性表的基本操作:1. 创建、初始化 线性表2. 事先给定 e, 返回其位序3. 事先给定 e,删除 e4. 有序表中, 插入 e5. 销毁线性表 二 (1)用带头结点的单链表表示多项式,表中每一个结点表示多项式中的一项 ;(2) 一元多项式简单计算器的基本功能为: 输入并建立多项式;输出多项式;两个多项式相减。(多项式的各项以指数形式输出)所属课程算法与数据结构实验目的通过本实验,基本掌握线性表的逻辑结构、存储结构及其建立、插入、删除等基本操作。通过相关算法的 C语言实现,并考虑线性表在多项式运算中的应用。实验内容(一)请通过 C 语言调用函数的方

2、式来实现线性表的基本操作:1. 创建、初始化 线性表2. 事先给定 e, 返回其位序3. 事先给定 e,删除 e4. 有序表中, 插入 e5. 销毁线性表 注意:通过适当的例子加以调试说明。(二)设计一个一元多项式简单的计算器。要求: (1)用带头结点的单链表表示多项式,表中每一个结点表示多项式中的一项 ;(2) 一元多项式简单计算器的基本功能为: 输入并建立多项式;输出多项式;两个多项式相减。(多项式的各项以指数形式输出)实验过程及结果#include#include#define List_Init_Size 100#define Listincrement 10#define OVERF

3、LOW 0#define OK 1#define ERROR 0typedef int ElemType;typedef int status;typedef structElemType *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;#include typ

4、edef 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“, printf(“exp: “); scanf(“%d“, while(c!=0) s=(node*)malloc(sizeof(node); s-coef=c; s-exp=e; r-next=s; status LocateElemList(sqList

5、 *L,ElemType e)int i=0;while(ilengthif(ilength)return i+1;else return 0;status DeleteList(sqList *L,ElemType i)ElemType e;ElemType *p,*q;if(iL-length)return ERROR;p=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;

6、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=for(p=p=q;-p);*(p+1)=*p;*q=e;+L-length;return OK;status DestoryList(sqList *L)r=s; printf(“coef:“); scanf(“%d“, printf(“exp: “); scanf(“%d“, r-ne

7、xt=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 pre=pre-next; p=p-next; else if(p-exp=q-exp) sum=p-coef-q-coef; if(sum!=0) p-coef=sum; pr

8、e-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; free(L);return OK;void main()int i,l,e;sqList a;InitList(printf(“Please input array 5 number:“);for(i=0;inext=q; pre=pre-next; q=q-next; if(p!=NULL) pre-next=p; else pre-next=q; v

9、oid 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(); print(ha); printf(“n“); printf(“input hb de xishu zhishu :n“); hb=create(); print(hb); printf(“n“); printf(“cha shi :n“); polyadd(ha,hb); print(ha); printf(“n“); multipoly(ha,hb); 总结很难,要多练习。教师评语

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 精品笔记

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。