| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1479 人关注过本帖
标题:最基础的顺序表问题
只看楼主 加入收藏
kinghao
Rank: 2
等 级:论坛游民
帖 子:15
专家分:16
注 册:2010-5-23
结帖率:75%
收藏
已结贴  问题点数:10 回复次数:3 
最基础的顺序表问题
#if!define(DEF_LINKLIST)
#define DEF_LINKLIST
typedef int ElemType;
typedef LNODE*LinkList;
typedef enum{ERROR,OK}status;





#include <stdio.h>
#include <conic.h>
#include <stdlib.h>
#define OK 1;
#define ERROR 0;
#define OVERFLOW 0;
void CreatList_L(Linklist &L,int n);
void GetElem_L(Linklist L,int a,int &e);
void ListInsert_L(Linklist &L,int c,int d);
void ListDelete(LinkList &L,int f,int &g);
typedef struct LNODE
{
    int data;
    struct LNODE *next;
}LNODE,*LinkList;
status InitList_L(LinkList &L)  /*建立一个只含头结点的空表*/
{
    L=(LinkList)malloc(sizeof(LNODE));
        if (!L)
            exit(OVERFLOW);
    L->next=NULL;
    return OK;
}
//////////////////////////////////////////////////////////////
void CreatList_L(LinkList&L,int n)  /*建立含n个元素的链表*/
{
    LinkList p,q;
    int i;
    printf("Input the data:");
    q=L;
    for(i=0,i<=n;i++)
    {
        p=(LinkList)malloc(sizeof(LNODE));
        scanf("%d",&p->data);
        p->next=q->next;  /*新元素插入链表尾*/
        q->next=p;
        q=p;
    }
    return OK;
}
void GetElem_L(LinkListL,int a,int &e) /*查找第a个元素,并赋值给e*/
{
    LinkList P;
    int b;
    P=L;
    b=0;
    while(P&&b<a)  /*查找第a个元素*/
    {
        P=P->next;
        ++b;
    }
    if(!P||b>a)
        return ERROR;
    e=P->data; /*取出第a个元素给e*/
    return OK;
}
void ListInsert_L(LinkList&L,int c,int d) /*在元素c前插入元素d*/
{
    LinkList p,s;
    int j;
    p=L;
    j=0;
    while(p&&j<c-1) /*查找第c-1个结点*/
    {
        p=p->next;
        ++j;
    }
    if {!p||j>i-1}
    return ERROR;
    s=(LinkList)malloc(sizeof(LNODE)); /*申请一个新的结点*/
    s->data=d;
    s->next=p->next;
    p->next=s;
    return OK;
void ListDelete_L(LinkList&L,int f,int &g) /*删除第f个结点,并用g返回其值*/
{
    LinkList p,q;
    int m;
    p=L;
    m=0;
    while (p->next&&m<f-1) /*找第f个结点,用p指向前一个*/
    {
        p=p->next;
        ++m;
    }
    if(!(p->next)||j>i-1)
        return ERROR;
    q=p->next; /*q指向第f个结点*/
    p->next=q->next; /*删除第f个结点*/
    g=q->data;
    free(q);
    return OK;
}
void TraverseList_L(LinkList L)
{
    LinkList z
        z=L->next;
    while(p)
    {
        printf("%d",z->data);
        z=z->next;
    }
    return OK;
}
////////////////////////////////////////////////////
void main()
{
    int n,i,e,a,c,d,f,g;
    LinkList L;
    InitList_L(L);
    printf("Input the length of the list L:");
    scanf("%d",&n);
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CreatList_L(L,n);
    printf("output the datas:");
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    printf("Input the search location:");
    scanf("%d",&i);
    if(GetElem_L(L,a,e))
        printf("The data in the location %d is %d\n",a,e);
    else
        printf("can't find the location!\n");
    printf("output the data %d\n",e);
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    printf("Input the insert location:");
    scanf("%d",&i);
    printf("Input the insert data:");
    scanf("%d",&e);
    if(ListInsert_L(L,c,d))
    printf("output the data:%d\n",d);
    else
        printf("can't insert the data!");
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    printf("Input the delete location:);
    scanf("%d",&i);
    if (LinkDelete_L(L,f,g));
    printf("output the data:%d"\n,g);
    else
    printf("can't find the delete data!\n");
}




头文件是这样的,然后就是对链表进行插入查找删除,但老是说标识符未找到!
是头文件的问题?但学的不好,求解,谢谢
搜索更多相关主题的帖子: 顺序 基础 
2010-10-11 21:41
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:3 
那里?标识符未定义?
你可以给错误信息吗?
2010-10-12 12:50
kinghao
Rank: 2
等 级:论坛游民
帖 子:15
专家分:16
注 册:2010-5-23
收藏
得分:0 
回复 2楼 含苞含笑
1>d:\program files\链表\链表\main.cpp(4) : error C2065: “LinkList”: 未声明的标识符
1>d:\program files\链表\链表\main.cpp(4) : error C2146: 语法错误 : 缺少“;”(在标识符“L”的前面)
1>d:\program files\链表\链表\main.cpp(4) : error C2065: “L”: 未声明的标识符
1>d:\program files\链表\链表\main.cpp(5) : error C2065: “L”: 未声明的标识符
1>d:\program files\链表\链表\main.cpp(5) : error C3861: “InitList_L”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(6) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(7) : error C3861: “scanf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(9) : error C2065: “L”: 未声明的标识符
1>d:\program files\链表\链表\main.cpp(9) : error C3861: “CreatList_L”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(10) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(12) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(13) : error C3861: “scanf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(14) : error C2065: “L”: 未声明的标识符
1>d:\program files\链表\链表\main.cpp(14) : error C3861: “GetElem_L”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(15) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(17) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(18) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(20) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(21) : error C3861: “scanf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(22) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(23) : error C3861: “scanf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(24) : error C2065: “L”: 未声明的标识符
1>d:\program files\链表\链表\main.cpp(24) : error C3861: “ListInsert_L”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(25) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(27) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(29) : error C2001: 常量中有换行符
1>d:\program files\链表\链表\main.cpp(30) : error C2146: 语法错误 : 缺少“)”(在标识符“scanf”的前面)
1>d:\program files\链表\链表\main.cpp(31) : error C2065: “L”: 未声明的标识符
1>d:\program files\链表\链表\main.cpp(29) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(31) : error C3861: “LinkDelete_L”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(32) : warning C4390: “;”: 找到空的受控语句;这是否是有意的?
1>d:\program files\链表\链表\main.cpp(32) : error C2017: 非法的转义序列
1>d:\program files\链表\链表\main.cpp(32) : error C2146: 语法错误 : 缺少“)”(在标识符“n”的前面)
1>d:\program files\链表\链表\main.cpp(32) : error C2059: 语法错误 : “)”
1>d:\program files\链表\链表\main.cpp(33) : error C2181: 没有匹配 if 的非法 else
1>d:\program files\链表\链表\main.cpp(32) : error C3861: “printf”: 找不到标识符
1>d:\program files\链表\链表\main.cpp(34) : error C3861: “printf”: 找不到标识符
1>运行.cpp
1>d:\program files\链表\链表\运行.cpp(1) : error C2065: “LinkList”: 未声明的标识符
1>d:\program files\链表\链表\运行.cpp(1) : error C2065: “L”: 未声明的标识符
1>d:\program files\链表\链表\运行.cpp(1) : error C2062: 意外的类型“int”
1>d:\program files\链表\链表\运行.cpp(2) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>d:\program files\链表\链表\运行.cpp(2) : error C2447: “{”: 缺少函数标题(是否是老式的形式表?)
1>d:\program files\链表\链表\运行.cpp(17) : error C2065: “LinkListL”: 未声明的标识符
1>d:\program files\链表\链表\运行.cpp(17) : error C2062: 意外的类型“int”
1>d:\program files\链表\链表\运行.cpp(18) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>d:\program files\链表\链表\运行.cpp(18) : error C2447: “{”: 缺少函数标题(是否是老式的形式表?)
1>d:\program files\链表\链表\运行.cpp(33) : error C2065: “LinkList”: 未声明的标识符
1>d:\program files\链表\链表\运行.cpp(33) : error C2065: “L”: 未声明的标识符
1>d:\program files\链表\链表\运行.cpp(33) : error C2062: 意外的类型“int”
1>d:\program files\链表\链表\运行.cpp(34) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>d:\program files\链表\链表\运行.cpp(34) : error C2447: “{”: 缺少函数标题(是否是老式的形式表?)
1>d:\program files\链表\链表\运行.cpp(81) : fatal error C1004: 发现意外的文件尾
谢谢纠正!!
2010-10-12 18:01
快速回复:最基础的顺序表问题
数据加载中...
 
   



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

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