我又来问问题了.老规100分
GR 2003-11-27 07:27:01 ***********
//头文件//
#define TRUE 1
#define FALSE 0
typedef char ElemType;
typedef struct DataTag
{int i;
DataTag* next;
}Node,*pNode;
typedef struct Tag {
ElemType *elem;
int lenth;
int listsize;
}SqlList,*pSqlList;
//cpp///////////////
***************************************************************************
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#include <stdio.h>
#include <malloc.h>
#include <structdata.h>
pSqlList InitList(pSqlList L)
{
L->elem = (ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L->elem)
return 0;
L->lenth = 0;
L->listsize = LIST_INIT_SIZE;
return L;
}
//函数功能:初始化.
void DestryList()
{}
//函数功能:销毁
bool Compare(ElemType p,ElemType e)
{ if (p == e)
return TRUE;
return FALSE;
}
//函数功能:判断是否满足关系
bool ListEmpty(pSqlList L)
{
if(L)
return TRUE;
else
return FALSE;
}
//函数功能:判定是否为空
int ListLenth(pSqlList L)
{ if(ListEmpty(L))
return 0;
int i = L->lenth;
return i;
}
//函数功能:返回数组个数
void GetElem()
{}
//函数功能:取i位置值
int LocateElem(pSqlList L,ElemType e,int*(Compare)(ElemType,ElemType))
{
int i=1;
ElemType* p =L->elem;
while( i < L->lenth && !Compare(*p,e))
{ i++; p++; }
if( i < L->lenth )
return i;
else
return 0;
}
//函数功能:找满足关系的函数.找到返回序号.失败:0
//实现步骤:递增序号i和数组p地址.调用cmpare()找不到继续递增.
int ListInsert(pSqlList L,int i,ElemType e)
{
if( i<1 || i > L->lenth+1) //i不合法)
return 0;
if(L->lenth >= L->listsize) //空间满了)
{
ElemType* newbase = (ElemType*)realloc(L->elem, (L->listsize + LISTINCREMENT)*sizeof(ElemType));//加长,分配空间
if(!newbase) //分配失败
return 0;
L->elem = newbase;
}
ElemType* q = &(L->elem[i-1]); //q为要插入的地址
for(ElemType* p =&(L->elem[L->lenth -1]); p>=q; p--)
*(p+1) = *p; //往后推进一各
*q=e; //插入动作;
L->lenth++;//表长加一;
return 1;
}
//函数功能:插入
//实现步骤1.判定 i序号是否合法.2.判断表是否满.,满则分配3.具体插入
ElemType Listdel(pSqlList L,int i) //第三个参数为将来
{
if( i<0 || i>L->lenth) //不合法
return 0;
ElemType* p = &(L->elem[i-1]); //被删除的位置
ElemType e = *p;
p++;
ElemType* q = &(L->elem[L->lenth -1]);
for(p; p<=q; p++)
*(p-1) = *p;
return e;
}
//函数功能:删除
//实现步骤 1:判定i序号是否合法.2.具体插入
void main()
{
SqlList A;
pSqlList LA= InitList(&A);
char a='a';
for(int i =1; i < 200; i++)
{
int n = ListInsert(LA,i,a);
printf("%c%d\n%d\n",LA->elem[0],LA->lenth,i);
}
int n = ListInsert(LA,50,'b');
printf("%c%d%d\n",LA->elem[i-1],LA->lenth,i);
ElemType e = Listdel(LA,50); //删除测试
printf("%c\n",e);
}
我要问的是.为什么测试出来局部空间居然可以达到312个字符.不是说预设的stack只有1M么?
为什么。??
加了注释之后copy上来的代码老是行列有点乱。。。~~