首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

哪位高手帮小弟我看看这个程序如何改才好用啊

2012-05-02 
谁帮我看看这个程序怎么改才好用啊?刚学数据结构,要编一个线性表顺序存储结构并实现插入和删除的一个程序,

谁帮我看看这个程序怎么改才好用啊?
刚学数据结构,要编一个线性表顺序存储结构并实现插入和删除的一个程序,C语言版的
我想是自己输入几个数据然后在处理,但是这个程序运行不了,谁帮我看看怎么回事啊
跪求。。。是不是主函数的地方出错了啊?



#include<stdio.h>
#include<alloc.h>
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 2
#define OVERFLOW -2
#define OK 1
#define ERROR 0
typedef int ElemType;
typedef int Status;

typedef struct
{
 ElemType *elem;
 int length;
 int listsize;
}SqList;


Status Initlist(SqList *L)
{
 (*L).elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
 if(!(*L).elem)
  exit(OVERFLOW);
 (*L).length=0;
 (*L).listsize=LIST_INIT_SIZE;
 return OK;
}

Status ListInsert(SqList *L,int i,ElemType e)
{
 ElemType *newbase,*q,*p;
 if(i<1||i>(*L).length+1)
  return ERROR;
  if((*L).length>=(*L).listsize)
  {
  newbase=(ElemType*)realloc((*L).elem,((*L).listsize+LISTINCREMENT)*sizeof(ElemType));
  if(!newbase)
  exit(OVERFLOW);
  (*L).elem=newbase;
  (*L).listsize+=LISTINCREMENT;
  }
  q=(*L).elem+i-1;
  for(p=(*L).elem+(*L).length-1;p>=q;--p)
  *(p+1)=*p;
  *q=e;
  ++(*L).length;
  return OK;
}

Status ListDelete(SqList *L,int i,ElemType *e)
{
  ElemType *p,*q;
  if(i<1||i>(*L).length)
  return ERROR;
  p=(*L).elem+i-1;
  *e=*p;
  q=(*L).elem+(*L).length-1;
  for(++p;p<=q;++p)
  *(p-1)=*p;
  --(*L).length;
  return OK;
}

void main()
{
 SqList *L;
 int j,e,i,m;
 Initlist(L);
 printf("\nthe data have input are:");
 scanf("%2d",&j);
  printf("%d\t",(*L).elem[j]);
 printf("\nPlease choose insert or delete(1/0):");
 scanf("%d\n",&m);
 if(m==1)
  {scanf("%d,%d",&i,&e);
  ListInsert(L,i,e);
  for(j=0;j<=5;j++)
  printf("%d\t",(*L).elem[j]);
  }
 else
  {
  scanf("%d",&i);
  ListDelete(L,i,&e);
  for(j=0;j<4;j++)
  printf("%d\t",(*L).elem[j]);
  }
}
 

[解决办法]

探讨
哦,谢谢啊
但是单步调试是个什么东西。。。。。

热点排行