好文档 - 专业文书写作范文服务资料分享网站

华农数据结构上机实验标准答案

天下 分享 时间: 加入收藏 我要投稿 点赞

数据结构上机答案

1.1顺序线性表的基本操作

#include<stdio.h> #include #define OK 1 #define ERROR 0

#define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define ElemType int

typedef struct { int *elem,length,listsize; }SqList;

int InitList_Sq(SqList &L) { L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType)); L.length=0;

?L.listsize=LIST_INIT_SIZE; ?return OK; }

int Load_Sq(SqList &L) { ?int i; if(L.length==0) ?printf(\The List is empty!\?else ?{

? printf("The List is:\; ?for(i=0;i<L.length;i++) ??printf(\d",L.elem[i]); } printf(\"); ?return OK; }

int ListInsert_Sq(SqList &L,int i,int e) { if(i<1||i>L.length+1) return ERROR; ElemType *newbase,*q,*p; if(L.length>=L.listsize)

{ ?newbase=(ElemType*)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(ElemType)); ??L.elem=newbase;

? L.listsize+=LISTINCREMENT; }

?q=&(L.elem[i-1]);

?for(p=&(L.elem[L.length-1]);p>=q;--p) *(p+1)=*p; ?*q=e; ++L.length; return OK; }

int ListDelete_Sq(SqList &L,int i,int &e) {

?ElemType *q,*p; ?if(i<1||i>L.length) ?return ERROR; ?p=&(L.elem[i-1]); e=*p; q=L.elem+L.length-1; for(++p;p<=q;p++) ? *(p-1)=*p; L.length--; return OK; }

int main() { SqList T; ?int a,i;

?ElemType e,x; if(InitList_Sq(T)) { printf(\Sequence List Has Created.\\n\); } while(1) { printf(\1:Insert element\\n2:Delete element\n3:Load all elements\n0:Exit\\nPlease choose:\\n\); ??scanf("%d\); ?switch(a) ?{

华农数据结构上机实验标准答案

数据结构上机答案1.1顺序线性表的基本操作#include#include#defineOK1#defineERROR0#defineLIST_INIT_SIZE100#defineLISTINCREMENT10#defineElemTypeinttypede
推荐度:
点击下载文档文档为doc格式
6dhwh48fvm7wp9920czo7b3ef97x1a0101x
领取福利

微信扫码领取福利

微信扫码分享