数据结构__图书管理系统(C语言)

本篇文章用于记录数据结构的实验一,模拟图书管理系统。

数据结构__图书管理系统(C语言)_第1张图片

 代码如下:

#include
#include
#include

#define OK 1
#define ERROR 0
#define INITSIZE 100
#define INCREMENT 10

typedef int status;

typedef struct{
	char ISBN[15];
	char title[50];
	char writer[40];
	char publisher[30];
	float price;
}Book;//定义图书类型 

typedef struct{
	Book *elem;
	int length;
	int listsize;
}SqList;//定义顺序线性表的类型 

status InitList_Sq(SqList &L)//初始化一个空表
{
   L.elem=(Book *) malloc(INITSIZE*sizeof(Book));
   if(!L.elem) exit(-1);
   L.length=0;
   L.listsize=INITSIZE;
   
   return OK; 
}

int LocateBook(SqList L,char *ISBN)//查找 
{
	for(int i=0;i=L.listsize) {
		p =(Book *)realloc(L.elem,(L.listsize+INCREMENT)*sizeof(Book));
		if(!p){
			exit(-1);
		}
		L.elem=p;
		L.listsize+=INCREMENT;
	}
	L.elem[L.length]=e;
	L.length++;
	
	return OK;
}

status DeleteBook(SqList &L,char ISBN[],Book &e)//删除 
{
    int i,j;
	if((i=LocateBook(L,ISBN))==0){
		return ERROR;
	}
	e=L.elem[i-1];
	for(j=i;jL.length) return ERROR;
    L.elem[i-1]=e;
    return OK;
}  

void sort(SqList &L)//排序 
{
	int flag;
	for(int i=0;i<=L.length-2;i++)
	{
	  flag=1;
	  for(int j=0;j<=L.length-i-2;j++)
	  {
	  	if(strcmp(L.elem[j].ISBN,L.elem[j+1].ISBN)>0)
	  	{
	  	  Book e=L.elem[j];
		  L.elem[j]=L.elem[j+1];
		  L.elem[j+1]=e;
		  flag=0;	
		}
	  }
	  if(flag==1)
	    break;
    }
}

int length(SqList L)
{
	return L.length;
}  //返回长度 

void print(Book e)
{
	printf("%-18s%-30s%-20s%-20s%-8.2f\n",e.ISBN,e.title,e.writer,e.publisher,e.price);
} //打印函数 

void display(SqList L)
{
	for(int i=0;i

完结!!!1

你可能感兴趣的:(数据结构__图书管理系统(C语言))