您的位置:首页 > 理论基础 > 数据结构算法

记录我的数据结构(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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: