记录我的数据结构(C语言)学习历程(2017年3月30号开始):
2017-04-08 02:34
746 查看
c
//main.c#include<stdio.h>#include<stdlib.h>#include<malloc.h>#include "List.h"int main(void){//char a[]="Error"; //int i;// FatalError(a);//List L,q;// CreateList(&L,8);// PrintList(L);// InsertH(6,L,L);//printf("%d\n",IsEmpty(L)); //q=Find(7,L); //i=q->Element;//printf("%d",i);// PrintList(L);// MakeEmpty(L); //DeleteList(L);//printf("%d\n",IsEmpty(L));List L1_1,L2_1,L3_1;ElementType n1,n2;printf("请输入第一个多项式的项数:");scanf("%d",&n1); printf("\n");printf("请输入第一个多项式的系数和指数:"); printf("\n");CreateList(&L1_1,n1);PrintList(L1_1);printf("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");printf("\n请输入第二个多项式的项数:");scanf("%d",&n2); printf("\n");printf("请输入第二个多项式的系数和指数:"); printf("\n");CreateList(&L2_1,n2);PrintList(L2_1);printf("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");L3_1=MultPolynomial(L1_1,L2_1);PrintList(L3_1);}%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5//List.h#ifndef _LIST_H_typedef int ElementType;struct Node;typedef struct Node *PtrToNode;typedef PtrToNode List;typedef PtrToNode Position;/*struct Node{ElementType Element;Position Next;};*/struct Node{ElementType Cofficient;ElementType Exponent;Position Next;};void CreateList(List *L,int n);void PrintList(List L);List MakeEmpty(List L);void CreateEmptyList(List *L);int IsEmpty(List L);int IsLast(Position P,List L);Position Find(ElementType X,List L);void Delete(ElementType X,ElementType Y,List L);Position FindPrevious(ElementType X,List L);void Insert(ElementType X,ElementType Y,List L,Position P);void InsertH(ElementType X,ElementType Y,List L,Position P);void DeleteList(List L);Position Header(List L);Position First(List L);Position Advance(Position P);ElementType Retrieve(Position P);List MultPolynomial(List L1,List L2); #endif %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//List.c #include "List.h"#include<s d4e6 tdio.h>#include<stdlib.h>#include<malloc.h>/*struct Node{ElementType Element;Position Next;};*/void CreateList(List *L,int n){Position P,P1;int i;*L=(Position)malloc(sizeof(struct Node));(*L)->Next=NULL;P1=*L;printf("请输入%d对数据(以空格隔开):\n",n); //没问题 for(i=n;i>0;i--){//P=(Position)malloc(sizeof(struct Node)); //scanf("%d",&P->Element); //前插 //P->Next=(*L)->Next; //(*L)->Next=P;P=(Position)malloc(sizeof(struct Node));scanf("%d",&P->Cofficient);scanf("%d",&P->Exponent);P->Next=P1->Next; //后插 P1->Next=P;P1=P;}}void PrintList(List L){printf("已保存链表\n");Position P;P=L->Next;while(P->Next!=NULL){printf("%d ",P->Cofficient); //没问题 printf("%d ",P->Exponent);P=P->Next;} printf("%d ",P->Cofficient); //没问题 printf("%d ",P->Exponent);}void FatalError(char a[]){printf("%s",a); //没问题 }int IsEmpty(List L){return L->Next==NULL; //没问题 }int IsLast(Position P,List L){return P->Next==NULL; //没问题 }List MakeEmpty(List L){List q,p;p=L->Next;while(p!=NULL){ //没问题 q=p->Next;free(p);p=q;}L->Next=NULL;return L;}Position Find(ElementType X,List L){Position P;P=L->Next;while((P!=NULL)&&(P->Exponent!=X)) //没问题 {P=P->Next;}return P;}Position findPrevious(ElementType X,List L)</s
相关文章推荐
- 记录我的数据结构(C语言)学习历程(2017年3月30号开始):
- 记录我的数据结构(C语言)学习历程(2017年3月30号开始)
- C语言学习历程(十九) 数据结构完成停车场项目
- C语言学习历程(十七)数据结构与排序(冒泡、选择、希尔排序)算法
- 开始记录我的学习历程
- 今天开始记录我的嵌入式学习历程
- 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始
- 准备开始写blog,记录自己的学习历程,欢迎各位指点。
- 从今天开始,记录自己的学习历程!
- 2015.6.28开始写博客记录cocos2dx学习历程
- 开始记录自己的学习历程
- Python学习记录-3-简明Python教程-数据结构
- 数据结构及算法 1-开始学习!
- 开始写博,记录学习历程
- 今天开始记录学习历程2016-10-25
- 2级C语言可能没过,数据结构必须开始,第一个目标手写程序突破100行
- C语言学习笔记之数据结构篇(二)
- 数据结构 学习笔记之:静态链表--史上最简单的C语言实现——只为掌握概念——不清楚静态链表的鸟鸟们有福了!
- 【Opengl es】开始学习opengl es,记录学习历程与心得。
- 2017年1月22日,我打算开始记录自己接下来的学习、生活、工作历程。