愿你 发表于 2018-3-15 21:27:37

求各位大神解答这种错误是什么原因???

什么原因????

ba21 发表于 2018-3-15 21:54:07

上代码

BngThea 发表于 2018-3-16 07:40:30

括起来

愿你 发表于 2018-3-16 09:41:34

ba21 发表于 2018-3-15 21:54
上代码

#include<stdio.h>
#include<malloc.h>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
#define INIT_SIZE 5
#define INCREM 5
#define ERROR 0
#define OK 1
typedef&nbsp;&nbsp;int ElemType;
typedef struct {&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;//×
&nbsp; &nbsp; &nbsp; &nbsp; ElemType *slist;
&nbsp; &nbsp; &nbsp; &nbsp; int length;
&nbsp; &nbsp; &nbsp; &nbsp; int listsize;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; //×&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;//不知道定义来干嘛
}Sqlist;
int InitList_sq(Sqlist *L);
int CreateList_sq(Sqlist *L,int n);&nbsp;&nbsp;
int ListInsert_sq(Sqlist *L,int i,ElemType e);
int PrintList_sq(Sqlist *L);
int ListDelete_sq(Sqlist *L,int i);
void ListLocate(Sqlist *L,ElemType e);

//初始化顺序表(建立空表)
int InitList_sq(Sqlist *L){
&nbsp; &nbsp; &nbsp; &nbsp; L.slist=(ElemType*)malloc(INIT_SIZE*sizeof(ElemType));
&nbsp; &nbsp; &nbsp; &nbsp; if(!L.slist) return ERROR;
&nbsp; &nbsp; &nbsp; &nbsp; L.length=0;
&nbsp; &nbsp; &nbsp; &nbsp; // L.listsize=INIT_SIZE; //不知道什么用处
&nbsp; &nbsp; &nbsp; &nbsp; return OK;
}


//创建顺序表
int CreateList_sq(Sqlist *L,int n){
&nbsp; &nbsp; &nbsp; &nbsp; ElemType e;
&nbsp; &nbsp; &nbsp; &nbsp; int i;
&nbsp; &nbsp; &nbsp; &nbsp; for(i=0;i<n;i++)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("input data %d:",i+1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%d",&e);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /*&nbsp;&nbsp;if(!ListInsert_sq(L,i+1,e))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ERROR;&nbsp;&nbsp;*/
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; return OK;
}

// 输出顺序表中的元素
int PrintList_sq(Sqlist *L){
&nbsp; &nbsp; &nbsp; &nbsp; int i;
&nbsp; &nbsp; &nbsp; &nbsp; for(i=1;i<=L.length;i++)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("%5d",L.slist);
&nbsp; &nbsp; &nbsp; &nbsp; return OK;
}

//在顺序表中插入
int ListInsert_sq(Sqlist *L,int i,ElemType e)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int k;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(i<1||i>L.length+1)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ERROR;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(k=L.length-1;k>=i-1;k--)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L.slist=L.slist;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L.slist=e;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L.length++;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return OK;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return OK;
&nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; //在顺序中删除第i个元素
int ListDelete_sq(Sqlist *L,int i)
{
&nbsp; &nbsp; &nbsp; &nbsp; int j;
&nbsp; &nbsp; &nbsp; &nbsp; if((i<1)||(i >L.length))
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return ERROR;
&nbsp; &nbsp; &nbsp; &nbsp; for(j=i;j<=L.length-1;j++)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; L.slist =L.slist;
&nbsp; &nbsp; &nbsp; &nbsp; --L.length;
&nbsp; &nbsp; &nbsp; &nbsp; return OK;
}

//在顺序表中查找指定值元素,返回其序号
void ListLocate(Sqlist *L,ElemType e)
{
&nbsp; &nbsp; &nbsp; &nbsp; int i,z=0;
&nbsp; &nbsp; &nbsp; &nbsp; for(i=0;i<L.length-1;i++)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(L.slist==e)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("该值所在表中的序号为:第%d位",i+1);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; z=1;
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; if(z==0)
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("没有该值\n");
}

//主函数
int main()
{
&nbsp; &nbsp; &nbsp; &nbsp; Sqlist sl,L;
&nbsp; &nbsp; &nbsp; &nbsp; int n,i,e;
&nbsp; &nbsp; &nbsp; &nbsp; printf("*********************欢迎来到该界面******************");
&nbsp; &nbsp; &nbsp; &nbsp; printf("please input n(输入顺序表个数):");
&nbsp; &nbsp; &nbsp; &nbsp; scanf("%d",&n);
&nbsp; &nbsp; &nbsp; &nbsp; if(n>0)
&nbsp; &nbsp; &nbsp; &nbsp; {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n1-Create Sqlist:\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InitList_sq(&sl);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CreateList_sq(&sl,n);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("输入要插入的值和序号:");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%d %d",&i,&e);&nbsp;&nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListInsert_sq(&sl,i,e);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("输出插入后的顺序表:");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PrintList_sq(&sl);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("输入要删除的值元素的序号:");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%d",&i);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListDelete_sq(&sl,i);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("输出删除后的元素的顺序表:\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PrintList_sq(&sl);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("\n");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("输入要查找的值:");
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scanf("%d",&e);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ListLocate(&sl, e);
&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; else
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf("ERROR");
&nbsp; &nbsp; &nbsp; &nbsp; return 0;
}

愿你 发表于 2018-3-16 09:43:19

ba21 发表于 2018-3-15 21:54
上代码

刚才那个发错了 不知道为啥复制过去是那样的...
应该是下面这个


#include<stdio.h>
#include<malloc.h>               
#define INIT_SIZE 5
#define INCREM 5
#define ERROR 0
#define OK 1
typedefint ElemType;
typedef struct {               //×
        ElemType *slist;
        int length;
        int listsize;          //×      //不知道定义来干嘛
}Sqlist;
int InitList_sq(Sqlist *L);
int CreateList_sq(Sqlist *L,int n);
int ListInsert_sq(Sqlist *L,int i,ElemType e);
int PrintList_sq(Sqlist *L);
int ListDelete_sq(Sqlist *L,int i);
void ListLocate(Sqlist *L,ElemType e);

//初始化顺序表(建立空表)
int InitList_sq(Sqlist *L){
        L.slist=(ElemType*)malloc(INIT_SIZE*sizeof(ElemType));
        if(!L.slist) return ERROR;
        L.length=0;
        // L.listsize=INIT_SIZE; //不知道什么用处
        return OK;
}


//创建顺序表
int CreateList_sq(Sqlist *L,int n){
        ElemType e;
        int i;
        for(i=0;i<n;i++)
        {
                printf("input data %d:",i+1);
                scanf("%d",&e);
                /*if(!ListInsert_sq(L,i+1,e))
                        return ERROR;*/
        }
        return OK;
}

// 输出顺序表中的元素
int PrintList_sq(Sqlist *L){
        int i;
        for(i=1;i<=L.length;i++)
                printf("%5d",L.slist);
        return OK;
}

//在顺序表中插入
int ListInsert_sq(Sqlist *L,int i,ElemType e)
        {
                int k;
                if(i<1||i>L.length+1)
                        return ERROR;
                else
                {
                        for(k=L.length-1;k>=i-1;k--)
                                L.slist=L.slist;
                        L.slist=e;
                        L.length++;
                        return OK;
                }
                return OK;
        }

        //在顺序中删除第i个元素
int ListDelete_sq(Sqlist *L,int i)
{
        int j;
        if((i<1)||(i >L.length))
                return ERROR;
        for(j=i;j<=L.length-1;j++)
                L.slist =L.slist;
        --L.length;
        return OK;
}

//在顺序表中查找指定值元素,返回其序号
void ListLocate(Sqlist *L,ElemType e)
{
        int i,z=0;
        for(i=0;i<L.length-1;i++)
        {
                if(L.slist==e)
                        printf("该值所在表中的序号为:第%d位",i+1);
                z=1;
        }
        if(z==0)
                printf("没有该值\n");
}

//主函数
int main()
{
        Sqlist sl,L;
        int n,i,e;
        printf("*********************欢迎来到该界面******************");
        printf("please input n(输入顺序表个数):");
        scanf("%d",&n);
        if(n>0)
        {
                printf("\n1-Create Sqlist:\n");
                InitList_sq(&sl);
                CreateList_sq(&sl,n);
                printf("输入要插入的值和序号:");
                scanf("%d %d",&i,&e);
                ListInsert_sq(&sl,i,e);
                printf("输出插入后的顺序表:");
                PrintList_sq(&sl);
                printf("\n");
                printf("输入要删除的值元素的序号:");
                scanf("%d",&i);
                ListDelete_sq(&sl,i);
                printf("输出删除后的元素的顺序表:\n");
                PrintList_sq(&sl);
                printf("\n");
                printf("输入要查找的值:");
                scanf("%d",&e);
                ListLocate(&sl, e);
        }
        else
                printf("ERROR");
        return 0;
}

愿你 发表于 2018-3-16 09:46:45

BngThea 发表于 2018-3-16 07:40
括起来

成员运算符优先级不是已经很高了吗???

BngThea 发表于 2018-3-16 09:54:46

愿你 发表于 2018-3-16 09:46
成员运算符优先级不是已经很高了吗???

自增的也不低

愿你 发表于 2018-3-16 09:58:21

BngThea 发表于 2018-3-16 09:54
自增的也不低

成员比自增高。。。

BngThea 发表于 2018-3-16 10:09:18

愿你 发表于 2018-3-16 09:58
成员比自增高。。。

ok, you win.

愿你 发表于 2018-3-16 10:51:22

BngThea 发表于 2018-3-16 10:09
ok, you win.

{:5_104:}

愿你 发表于 2018-3-26 17:35:26

这主要是.运算符和->的差别。前者由结构体变量引用。而后者是由指向结构体的指针变量引用
页: [1]
查看完整版本: 求各位大神解答这种错误是什么原因???