| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 603 人关注过本帖
标题:自己写的一段关于顺序线性表基本操作的代码,但是编译总是过不了
只看楼主 加入收藏
踩不扁小强
Rank: 2
等 级:论坛游民
帖 子:46
专家分:39
注 册:2013-4-6
结帖率:91.67%
收藏
已结贴  问题点数:20 回复次数:5 
自己写的一段关于顺序线性表基本操作的代码,但是编译总是过不了
下面的是我写的代码
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define ElemType int
#define OVERFLOW -2

typedef struct
{
    int *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;
}
// 算法2.3,构造一个空的线性表L,该线性表预定义大小为LIST_INIT_SIZE
// 请补全代码

int Load_Sq(SqList &L)
{
// 输出顺序表中的所有元素
    int i;
    if(L.length==0) printf("The List is empty!");  // 请填空
    else
    {
        printf("The List is: ");
        for(i=0;i<L.length;i++) printf("%d ",L.elem[i]);  // 请填空
    }
    printf("\n");
    return OK;
}

int ListInsert_Sq(SqList &L,int i,int e)
{
    int *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;
}




// 算法2.4,在顺序线性表L中第i个位置之前插入新的元素e
// i的合法值为1≤i≤L.length +1
// 请补全代码


int ListDelete_Sq(SqList &L,int i, int &e)
{
    int *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;
}



    // 算法2.5,在顺序线性表L中删除第i个位置的元素,并用e返回其值
// i的合法值为1≤i≤L.length
// 请补全代码



int main()
{
    SqList T;
    int a, i;
    ElemType e, x;
    if(InitList_Sq(T)==OK)    // 判断顺序表是否创建成功
    {
        printf("A Sequence List Has Created.\n");
    }
    while(1)
    {
        printf("1:Insert element\n2:Delete element\n3:Load all elements\n0:Exit\nPlease choose:\n");
        scanf("%d",&a);
        switch(a)
        {
            case 1: scanf("%d%d",&i,&x);
                    if(ListInsert_Sq(T,i,x)==0) printf("Insert Error!\n"); // 判断i值是否合法,请填空
                    else printf("The Element %d is Successfully Inserted!\n",x);
                    break;
            case 2: scanf("%d",&i);
                    if(ListDelete_Sq(T,i,e)==0) printf("Delete Error!\n"); // 判断i值是否合法,请填空
                    else printf("The Element %d is Successfully Deleted!\n",e);
                    break;
            case 3: Load_Sq(T);
                    break;
            case 0: return 1;
        }
    }
}
编译显示的错误我复制在下面:
--------------------Configuration: 顺序线性表的基本操作 - Win32 Debug--------------------
Compiling...
顺序线性表的基本操作.c
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(167) : error C2143: syntax error : missing ')' before '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(167) : error C2143: syntax error : missing '{' before '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(167) : error C2059: syntax error : '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(167) : error C2059: syntax error : ')'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(178) : error C2143: syntax error : missing ')' before '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(178) : error C2143: syntax error : missing '{' before '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(178) : error C2059: syntax error : '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(178) : error C2059: syntax error : ')'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(192) : error C2143: syntax error : missing ')' before '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(192) : error C2143: syntax error : missing '{' before '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(192) : error C2059: syntax error : '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(192) : error C2059: syntax error : ')'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(221) : error C2143: syntax error : missing ')' before '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(221) : error C2143: syntax error : missing '{' before '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(221) : error C2059: syntax error : '&'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(221) : error C2059: syntax error : ')'
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(249) : warning C4013: 'InitList_Sq' undefined; assuming extern returning int
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(260) : warning C4013: 'ListInsert_Sq' undefined; assuming extern returning int
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(264) : warning C4013: 'ListDelete_Sq' undefined; assuming extern returning int
F:\CYUYAN\数据结构\顺序线性表的基本操作.c(267) : warning C4013: 'Load_Sq' undefined; assuming extern returning int
执行 cl.exe 时出错.

顺序线性表的基本操作.obj - 1 error(s), 0 warning(s)
搜索更多相关主题的帖子: include return 线性表 
2013-09-28 22:12
踩不扁小强
Rank: 2
等 级:论坛游民
帖 子:46
专家分:39
注 册:2013-4-6
收藏
得分:0 
代码大多是我模仿书本的,自己看着好像也没问题,但是就是编译不了
2013-09-28 22:21
yuccn
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:0 
error C2143: syntax error : missing ')' before '&'

双击这样的提示信息,看看光标定位在那一行,细细看看有没有抄错

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-09-28 22:50
踩不扁小强
Rank: 2
等 级:论坛游民
帖 子:46
专家分:39
注 册:2013-4-6
收藏
得分:0 
回复 3楼 yuccn
没抄错呢,我在网上提交这份代码给老师的时候都通过了,但是在自己电脑就是编译不了,我不知道怎么回事
2013-09-28 22:53
toofunny
Rank: 4
等 级:业余侠客
帖 子:71
专家分:200
注 册:2012-7-22
收藏
得分:20 
源代码没有错。估计是你的源文件或者project出了问题。
新建一个工程,把网页这段代码拷贝进去重新编译一次看看。不要从原工程拷贝。
2013-09-28 23:02
踩不扁小强
Rank: 2
等 级:论坛游民
帖 子:46
专家分:39
注 册:2013-4-6
收藏
得分:0 
回复 5楼 toofunny
谢谢,按照你的方法已经通过编译了,太感谢了
2013-09-28 23:41
快速回复:自己写的一段关于顺序线性表基本操作的代码,但是编译总是过不了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015614 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved