欢迎光临散文网 会员登陆 & 注册

数据结构作业

2023-02-28 11:54 作者:日有所思-夜有所梦  | 我要投稿

#include <stdio.h>

#include <malloc.h>

#define MAXSIZE 50

typedef int Elem type

typedef struct

{

Elem type data[maxsize];

int length;


} sqlist

void Createlist(SQlist*&L,Elemtype a[],int n)

{

 L=(sqlist*)malloc(sizeof(Sqlist));

 for( i=0;i<n;i++)

L->;length=n;


}

void lnitlist(sqList*&L)

{

L=(SqList*)malloc(sizeof(sqList));

L->length=0;


}

void Destroy(Sqlist*&L)

{

free(L);


}

bool listEmpty(sqlist*L)

{

return (L->==0)a


}

int ListLength(Sqlist*L)

{

 return (L->length);


}

void Displist (SqList*L)

{


return (L->length);


}

void DispList(Sqlist*L)

{

for(int i=0;i<L->length;i++)

printf("%d",L->data[i]);


printf("\n");

}

bool GetELem(SqList*L,int i,Elem TYpe &e)

{

 if(i<1|| i>L-> length)

return false;

 e=L->data[i-1];

 return ture ;

}

int locateELem(sqlist*L,ElemType &e)

{

int i=0;

while (i<L->length && L->data[i]!=e)i++;

if(i>=L->length)

return 0;

else 

return i+1;


}

bool listlnsert(sqlist*&L,int i,Elem Type e)

{

int j;

if(i<1 || i>L->length)

return false;

i--;

for(j=L->length;j>i;j--)

L->data[j]=L->data[j-1];

L->data[i]=e;

L->length++;

return ture;



}

bool ListDelete(sqlist *&Lint i;ELemType &e)


{

int j;

if(i<1 || i>L->length)

retrun false;

i--;

e=L->data[j];

for(j=i;j<L-length-1;j++)

L->length--;

return ture;

}





}


数据结构作业的评论 (共 条)

分享到微博请遵守国家法律