sqlist.h

来自「线性表(顺序表)的创建」· C头文件 代码 · 共 74 行

H
74
字号
#include "stdio.h"
#include "malloc.h"
#define null 0
#define maxsize 1024
typedef char datatype;
typedef struct 
{   datatype data[maxsize];
    int last;
}sequenlist;
int insert (sequenlist*L,datatype x,int i)
{ int j;
  if (L->last==maxsize-1)
  {  printf ("overflow");
     return 0;
  }
  else if ((i<0)||(i<L->last))
  {
  	 printf ("error,please input the right 'i'");
     return 0;
  }
  else
  {
     for(j=L->last;j>=i;j--)
         L->data[j+1]=L->data[j];
         L->data[i]=x;
         L->last=L->last+1;
  }
  return(1);
}
int dellist(sequenlist*L,int i)
{   if ((i<0)||(i>L->last))
     { 
        printf ("error,please input the right i");
        return 0;  
     }
     else
     { 
        for(;i<L->last;i++)
            L->data[i]=L->data[i+1];
            L->last=L->last-1;
            return(1);
     }
}
void creatlist(sequenlist *L) 
{
	int n,i;
	char tmp;
	printf ("请输入数据的个数:\n");
	scanf ("%d",&n);
	for (i=0;i<n;i++)
	{
	   printf ("data[%d]=",i);
	   fflush(stdin);
	   scanf("%c",&tmp);
	   L->data[i]=tmp;
	}
	L->last=n-1;
	printf ("\n");
}
void printout (sequenlist *L)
{
	int i;
	for (i=0;i<=L->last;i++)
	{ 
	  printf ("data[%d]=",i);
	  printf("%c\n",L->data[i]);
	}
}
	

	
	
      

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?