次C语言程序哪里错了

来源:百度知道 编辑:UC知道 时间:2024/05/13 03:39:01
# include <stdio.h>
# define LIST_INIT_SIZE 10
# define LISTINCREMENT 10
# define ElemType int
# define OVERFLOW -1
# define OK 1
# define ERROR 0
typedef struct{
ElemType *elem;
int length;
int listsize;
}Sqlist;
int InitList_Sq(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);
}
int ListInsert_Sq(Sqlist L,int i,ElemType e){
ElemType *q,*p,*newbase;
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;

#include"stdlib.h"还有你的程序有很多地方有问题的!这个链表设计的不是很好,根本就没有连起来啊!
这又个例子你自己回去结合着书本上的看看吧!!
(没见你的函数返回的值的用处啊!??)
#include<stdio.h>
#include<stdlib.h>
typedef struct node *pointer;
struct node
{
int data;
pointer next;
};
pointer next,null,p,L,s,q;
int j,e,n,k;
creater(int n)
{
int i;
L=(struct node *)malloc(sizeof(struct node));
L->next-null;
s=L;
for(i=1;i<=n;i++)
{printf("\n输入数据%d:",i);
scanf("%d",&k);
p=(struct node *)malloc(sizeof(struct node));
p->data=k;
s->next=p;
s=p;
}
p->next=null;
}
print()
{pointer p;
p=L->next;
while(p)
{printf("\n%d",p->data);
p=p->next;
}
printf("\n");
}
insert(int i,int e)
{if(i<1||i>n+1)printf("不存在 i\n");
else
{j=0;p=L;