求解为什么不能运行?数据结构顺序表,我用的是Cfree5

the_left_you 发布于 2013/10/30 15:56
阅读 329
收藏 0


#include "status1.h"
#include "stdio.h"
#include "malloc.h"
#include "sqlist.h"

typedef int LElemType;

int main(void)

 SqList l; 
 int i;
  int x;
   InitSqList(&l,50);
   for(i = 1;i <= 5;i++)
   { 
    scanf("%d",&x);
     listInsert(&l,i,x);
   }
   printf("长度为:%d\n数据为:",listLength(l)) ;

  for(i=1;i<=listLength(l);i++)
  {  
   getElem(l,i,&x);
     printf(" %d ",x);
  }
 printf("请输入数据和位置:");
 scanf("%d,%d",&x,&i);
 listInsert(&l,i,x);
 printf("长度为:%d\n数据为:",listLength(l)) ;

  for(i=1;i<=listLength(l);i++)
  {
    getElem(l,i,&x);
     printf(" %d ",x);
  }
}//以上是主函数sqli1.c

#define ListSpaceIncr 20
typedef struct
    {
     LElemType *base;
        int length;
        int listSize;
    }SqList;   //定义
    Status InitSqList(SqList &L,int InitSize)
        {
            L.base=(LElemType*)malloc(InitSize*sizeof(LElemType));
            if(!L.base) return(OVERFLOW);
            L.length=0;
            L.listSize=InitSize;
            return OK;
        }   //初始化
    int listLength(SqList)
        {
            return L.length;
        }   //求长度
    Status lengthIsEmpty(SqList &L)
        {
            if(!L.length) return TRUE;
            else return FALSE;
        }   //判空
    void clearList(SqList &L)
        {
            L.length=0;
        }   //清空
    Status getElem(SqList L,int i,LElemType &e)
        {
            if(!L.length)return ERROR;
            e=L.base[i-1];
            return OK;
        }   //取元素
    int locateElem(SqList L,LElemType e)
        {
            int i=0;
            while(i<L.length&&!equal(L.base[i],e))
            i++;
            if(i<L.length)
            return i+1;
            else return 0;
        }   //按值查
    Status listInsert(SqList &L,int i,LElemType e)
        {
            LElemType *newBase;
            int j;
            if(i<1||i>L.length+1)return ERROR;
            if(L.length==L.listSize)
                {
                    newBase=(LElemType*)realloc(L.base,(L.listSize+ListSpaceIncr)*sizeof(LElemType));
                    if(!newBase)return OVERFLOW;
                    L.base=newBase;L.listSize+=ListSpaceIncr;
                }
            for(j=L.length-1;j>=i-1;j++)
                L.base[j+1]=L.base[j];
            L.base[i-1]=e;
            L.length++;
            return OK;
        }   //插入值
    Status listDelete(SqList &L,int i,LElemType &e)
        {
            int j;
            if(i<1||i>L.length)return ERROR;
            e=L.base[i-1];
            for(j=i;j<L.length;j++)
                L.base[j-1]=L.base[j];
            L.length--;
            return OK;
        }   //删除

   //以上是调用的头文件SqList.h

 

typedef  int  Status;
#define  TRUE  1  
#define  FALSE  0
#define  OK  1
#define  ERROR  0
#define  OVERFLOW  -2

 //以上调用的头文件Status1.h

求解啊啊啊  谢谢啦发到我邮箱285204547@qq.com   要上课不能及时看

 

加载中
返回顶部
顶部