📄 creatlist_l.c
字号:
#include<stdio.h>
#include"stdlib.h"
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define Elemtype int
#define OK 1
#define ERROR -1
typedef int Status;
typedef int bool;
struct sqlist{
Elemtype *elem;
int length;
int listsize;
}L;
Status Initlist_sq (sqlist &L) {
//构造一个线性表
L.elem=(Elemtype *)malloc(LIST_INIT_SIZE*sizeof(Elemtype);
if(!L.elem) exit(ERROR);//存储分配失败
L.length=0;
L.listsize=LIST_INIT_SIZE;
return 1;
}//Initlist_sq
Status fuzhi_sq(sqlist &L){
int *p=L.elem;
int i;
for(i=0;i<L.listsize;i++)
{scanf("%d",*p); ++P;++L.length;}
}
void dayin_sq(sqlist L){
int i;int *p=L.elem;
for(i=0;i<L.length;i++)
{printf("%d ",*p);++p;}
}
Status ListInsert_sq(sqlist &L,int i,Elemtype e){
//insert the number 'e' before the l.i
//i的合法值为1<=i<=L.length
Elemtype *p,*q,*newbase;
if(i<1||i>L.length) return ERROR;//i is illegal
if(L.length>=L.listsize){//当前存储空间已满,增加分配
newbase=(Elemtype *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(Elemtype));
if(!newbase) exit(ERROR);//failure in requst address
L.elem=newbase;//the new address
L.listsize+=LISTINCREMENT;//增加存储容量
}
for(q=&(L.elem[L.length-1]);p>=q;--p) *(p+1)=*p;
//插入位置及之后的元素右移
*q=e;//插入e
++L.length;//表长加一
return OK;
}//listInsert_sq
void main(){
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -