运行什么都不打印,调试卡在第一个函数。。
#include <stdio.h>
#include <stdlib.h>
#define SIZE 10
#define INCREASEMENT 10
typedef int EType;
typedef struct SqList{
EType * elem;
int length;
int size;
}SqList,*Ptr;
typedef Ptr SqPtr;
//function prototype
int List_Init(SqPtr L);
int List_Retrival(SqPtr L, int post, EType * elem );
int List_Locate(SqPtr L, EType elem, int * post);
int List_Insert(SqPtr L, int post, EType elem);
int List_Delete(SqPtr L, int post);
//funcion definition
int List_Init(SqPtr L)
{
int status=0;
L->size = SIZE;
L->length = 0;
L->elem = (EType*)malloc(sizeof(EType) * L->size);
if(L->elem == NULL)
status = 1;
return status;
}
int List_Retrival(SqPtr L, int post, EType * elem )
{
int status = 1;
if(L){
if(post >= 1 && post <= L->length){
*elem = L->elem[post - 1];
status = 0;
}
else status = 2;
}
return status;
}
int List_Locate(SqPtr L, EType elem, int * post)
{
int status = 2, i;
if(L == NULL)
status = 1;
for(i = 0; i < L->length; i++)
{
if(elem == L->elem[i]){
*post = i+1;
status = 0;
break;
}
}
return status;
}
int List_Insert(SqPtr L, int post, EType elem)
{
int status = 2, i;
if(post >= 1 && post <= L->length ){
if(L && L->length <= L->size){
for(i = L->length-1; i >= post-1; i--){
L->elem[i+1] = L->elem[i];
}
L->elem[post-1] = elem;
L->length++;
status = 0;
}
}
else status = 1;
return status;
}
int List_Delete(SqPtr L, int post)
{
int status = 2, i;
if(post >= 1 && post <= L->length ){
if(L){
for(i = post-1;i < L->length-1; i++ ){
L->elem[i] = L->elem[i+1];
}
L->length--;
status = 0;
}
}
else status = 1;
return status;
}
int main()
{
SqPtr LA, LB, LC;
int status_A, status_B, status_C;
int i, j, k = 1;
status_A = List_Init(LA);
status_B = List_Init(LB);
status_C = List_Init(LC);
printf("%d %d %d",status_A,status_B,status_C);
List_Insert(LA, 1, 1);
List_Insert(LA, 2, 3);
List_Insert(LA, 3, 5);
List_Insert(LB, 1, 2);
List_Insert(LB, 2, 4);
List_Insert(LB, 3, 5);
List_Insert(LB, 4, 6);
for(i = 0; i < LA->length; i++){
for(j = 0; j < LB->length; j++){
if(LA->elem[i] == LB->elem[j]){
status_C=List_Insert(LC,k,LA->elem[i]);
printf("%d\n",status_C);
k++;
break;
}
}
}
for(k = 0; k < LC->length; k++)
printf("%d ",LC->elem[k]);
return 0;
}