| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1073 人关注过本帖
标题:第一次敲线性表的代码 全是问题
取消只看楼主 加入收藏
月祭樱冢
Rank: 2
等 级:论坛游民
帖 子:83
专家分:97
注 册:2013-7-15
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:4 
第一次敲线性表的代码 全是问题
题目是删除线性表中元素值在【x,y】之间的元素。
这是参照书自己写的
程序代码:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define i 0

void CreateList(SqList *&L,int a[],int n)
{
    L=(SqList *)malloc(sizeof(SqList));
    for(;i<n;i++)
        L->data[i];
    L->length=n;[i]=a
}

int LocateElem(SqList *L,int e)
{
    while(i<L->length && L->data[i]!=e)
        i++;
    if(i>=L->length)
        return 0;
    else
        return i+1;
}

bool ListDelete(SqList *&L,int i,int t)
{
    int j;
    if(i<1 || i>L->length)
        return false;
    i--;
    for(j=i;j<L->length-t;j++)
        L->data[j]=L->data[j+t];
    L->length-=t;
    return ture;
}

void DispList(SqList *L)
{
    for(;i<L->length;i++)
        printf("%d",L->data[i]);
    printf("\n");
}

int main()
{
    void CreateList(SqList *&L,int a[],int n);
    int LocateElem(SqList *L,int e);
    bool ListDelete(SqList *&L,int i,int t);
    void DispList(SqList *L);
    int m,n,a[100],x,y,l;
    bool b;
    printf("请输入顺序数组a:\n");
    for(;i<100;i++)
    {
        scanf("%d",a[i]);
        if(a[i]=='\n') break;
    }
    printf("x=");
    scanf("%d",x);
    printf("y=");
    scanf("%d",y);
    l=strlen(a);
    CreateList(L,a[l],l);
    n=LocateElem(L,x);
    m=LocateElem(L,y);
    m=m-n-1;
    b=ListDelete(L,n,m);
    if(b==ture)
        DDispList(L);
    else
        printf("删除失败!\n");
    return 0;
}

这是编译器报的错  好多啊
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(6) : error C2143: syntax error : missing ')' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(6) : error C2143: syntax error : missing '{' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(6) : error C2059: syntax error : '&'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(6) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(14) : error C2143: syntax error : missing ')' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(14) : error C2143: syntax error : missing '{' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(14) : error C2059: syntax error : 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(14) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2061: syntax error : identifier 'ListDelete'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2059: syntax error : ';'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2143: syntax error : missing ')' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2143: syntax error : missing '{' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2059: syntax error : '&'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(36) : error C2143: syntax error : missing ')' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(36) : error C2143: syntax error : missing '{' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(36) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(37) : error C2054: expected '(' to follow 'L'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(45) : error C2143: syntax error : missing ')' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(45) : error C2143: syntax error : missing ';' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(45) : error C2059: syntax error : 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(45) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(46) : error C2143: syntax error : missing ';' before 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : error C2065: 'bool' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : error C2146: syntax error : missing ';' before identifier 'ListDelete'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : warning C4013: 'ListDelete' undefined; assuming extern returning int
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : error C2065: 'SqList' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : error C2297: '*' : illegal, right operand has type 'int ** '
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : error C2059: syntax error : 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(48) : error C2143: syntax error : missing ';' before 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(49) : error C2143: syntax error : missing ';' before 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(50) : error C2146: syntax error : missing ';' before identifier 'b'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(50) : error C2065: 'b' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(52) : error C2105: '++' needs l-value
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(54) : error C2065: 'a' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(54) : error C2109: subscript requires array or pointer type
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(55) : error C2109: subscript requires array or pointer type
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(58) : error C2065: 'x' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(60) : error C2065: 'y' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(61) : error C2065: 'l' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(61) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(61) : warning C4024: 'strlen' : different types for formal and actual parameter 1
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(62) : error C2109: subscript requires array or pointer type
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(63) : error C2065: 'n' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(63) : warning C4013: 'LocateElem' undefined; assuming extern returning int
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(64) : error C2065: 'm' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(67) : error C2065: 'ture' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(68) : warning C4013: 'DDispList' undefined; assuming extern returning int
执行 cl.exe 时出错.
搜索更多相关主题的帖子: 线性表 color 元素 
2013-11-12 23:13
月祭樱冢
Rank: 2
等 级:论坛游民
帖 子:83
专家分:97
注 册:2013-7-15
收藏
得分:0 
回复 2楼 pauljames
这点我特别注意了的

算法是程序的灵魂
2013-11-13 09:17
月祭樱冢
Rank: 2
等 级:论坛游民
帖 子:83
专家分:97
注 册:2013-7-15
收藏
得分:0 
回复 3楼 embed_xuel
能不能帮说下具体问题呢

算法是程序的灵魂
2013-11-13 09:17
月祭樱冢
Rank: 2
等 级:论坛游民
帖 子:83
专家分:97
注 册:2013-7-15
收藏
得分:0 
回复 8楼 azzbcc
c++里面的吧  还没学

算法是程序的灵魂
2013-11-13 21:56
月祭樱冢
Rank: 2
等 级:论坛游民
帖 子:83
专家分:97
注 册:2013-7-15
收藏
得分:0 
程序代码:
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#define MaxSize 50
typedef char ElemType;
typedef struct
{
    ElemType data[MaxSize];
       int length;
} SqList;
void createList(SqList *&L,int a[],int n)
{   int i;
    L=(SqList *)malloc(sizeof(SqList));
    for(i=0;i<n;i++)
        L->data[i]=a[i];
    L->length=n;
}
int LocateElem(SqList *L, ElemType e)    //按元素值查找
{
    int i=0;
    while (i<L->length && L->data[i]!=e)
        i++;                    //查找元素e
    if (i>=L->length)            //未找到时返回0
        return 0;
    else
        return i+1;                //找到后返回其逻辑序号
}
static bool ListDelete(SqList *&L,int i,int t)
{
    int j;
    if(i<1 || i>L->length)
        return false;
    for(j=i;j<L->length-t;j++)
        L->data[j]=L->data[j+t];
    L->length-=t;
    return true;
}
void DispList(SqList *L)    //输出线性表
{
    int i;
    for (i=0;i<L->length;i++)
        printf("%d ",L->data[i]);
    printf("\n");
}
int main()
{
    int i,m,n,x,y,l,a[MaxSize];
    SqList *L;
    bool b;
    printf("请输入顺序数组a:\n");
    for(i=0;i<MaxSize;i++)
    {
        scanf("%d",a[i]);
        if(a[i]=='\n')
            break;
    }
    printf("x=");
    scanf("%d",&x);
    printf("y=");
    scanf("%d",&y);
    l=sizeof(a)/sizeof(int);
    createList(L,a,l);
    n=LocateElem(L,x);
    m=LocateElem(L,y);
    m=m-n-1;
    b=ListDelete(L,n,m);
    if(b==true)
        DispList(L);
    else
        printf("删除失败!\n");
    return 0;
}
这是新代码  但是main函数中第一个for循环想要的功能在我的编译器上实现不了 (功能是希望输入回车时结束对数组的输入)不知道是不是程序的问题  

算法是程序的灵魂
2013-11-15 11:13
快速回复:第一次敲线性表的代码 全是问题
数据加载中...
 
   



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

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