| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 805 人关注过本帖
标题:求大神帮忙查错啊,数据结构。
只看楼主 加入收藏
qq267165295
Rank: 1
等 级:新手上路
帖 子:21
专家分:2
注 册:2012-1-6
收藏
 问题点数:0 回复次数:4 
求大神帮忙查错啊,数据结构。
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <iomanip.h>
#include <conio.h>


typedef bool Status;

#define  TRUE   1
#define  FALSE  0
#define  OK     1
#define  ERROR  0


以下是各种错误啊!头都大了!
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(177) : error C2039: 'link' : is not a member of 'DoubleNode'
        c:\documents and settings\administrator\桌面\实验1\实验1.cpp(26) : see declaration of 'DoubleNode'
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(184) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(184) : error C2143: syntax error : missing ';' before '*'
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(184) : error C2377: 'ResultNode' : redefinition; typedef cannot be overloaded with any other symbol
        c:\documents and settings\administrator\桌面\实验1\实验1.cpp(51) : see declaration of 'ResultNode'
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(184) : error C2059: syntax error : ')'
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(185) : error C2501: 'Result' : missing storage-class or type specifiers
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(185) : error C2239: unexpected token '{' following declaration of 'Result'
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(225) : error C2065: 'output' : undeclared identifier
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(253) : error C2146: syntax error : missing ';' before identifier 'Output'
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(254) : error C2143: syntax error : missing ';' before '}'
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(286) : error C2664: 'Search' : cannot convert parameter 2 from 'char' to 'student &'
        A reference that is not to 'const' cannot be bound to a non-lvalue
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(301) : error C2371: 'x' : redefinition; different basic types
        c:\documents and settings\administrator\桌面\实验1\实验1.cpp(237) : see declaration of 'x'
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(311) : error C2146: syntax error : missing ';' before identifier 'system'
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(343) : error C2601: 'main' : local function definitions are illegal
c:\documents and settings\administrator\桌面\实验1\实验1.cpp(387) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

typedef struct
{// 双向链表节点结构定义
    int num;         //学号
    char name[10];  //姓名
}student;
typedef student EType;


typedef struct DoubleNode
{   
    EType     data;
    DoubleNode    *plink;
    DoubleNode    *nlink;
} DoubleNode;
//双向链表节点


typedef struct
{
    int num;
}HeadEType;//表头结点结构定义

typedef struct
{   
    HeadEType     Hdata;
    DoubleNode    *first;
} DoubleChainList;
//链表的头


typedef struct
{        
    DoubleNode    *plink;
    DoubleNode    *nlink;
} ResultNode;//返回直接前驱和直接后驱的数据元素的地址结果


typedef DoubleChainList ChainList;
typedef DoubleNode ChainNode;

ChainList *L;

char re_choose[]={"\n选择非法,请输入正确的编号...\n"};


ChainList *Creat(ChainList *L)
{// 构造一个空链表

    L=new ChainList;//产生一个仅有表头结点的链表
    L->first=NULL;//first的值设为空(NULL)值
    return L;
};


void Menu_name()
     //作者信息
{   
    printf("\n\n\n\n\n\n\n");
    printf("              *************************************************\n");
    printf("                           学生信息双向链表\n\n");
    printf("                           制作:杨克\n");
    printf("                           班级:计科1101班\n");
    printf("                           学号: 1109050132\n");
    printf("                           指导老师: 孙夫雄\n");
    printf("              **************************************************\n");
    printf("\n\n\n\t\t");
}




Status Delete(DoubleChainList *L, int k )
{// 在双向链表L中删除第k个数据元素,如果不存在第k个元素返回出错状态码
    if (k < 1 || ! L->first) return ERROR;
    DoubleNode   * current = L->first;
    DoubleNode   * p;
    if (k == 1)         // 删除的是链表中第一个结点
    {
        p = current ->nlink;
        p ->plink = NULL;
        L->first = p;
    }
    else
    {
        DoubleNode   *q = L->first;
        for (int index = 1; index < k  && q ; index++)
            q = q->nlink;
        if(!q)   
            return ERROR;
            current = q;       // current 指向第k个结点
        q = current ->plink;  
        p = current ->nlink;
        q->nlink = p;
        p->plink = q;
    }
    delete current;         // 释放被删除结点current的空间
    return OK;
}


Status Insert(DoubleChainList *L, int k, EType &x )
{// 在双向链表L中第k个数据元素之后插入元素X运算
 // 如果不存在第K个元素或者线性表空间已满,则返回出错状态码        
        if (k < 0)
        return ERROR;

        int    index = 1;
        DoubleNode     *current= L->first;

        while (index < k && current)
        {//找第k个结点
            index++;
            current = current ->nlink;
        }

        if (k > 0 && ! current)
            return ERROR;

        DoubleNode   *q = new DoubleNode;
        q->data = x;

        if (k)
        {// 插入在current 之后, 两个方向的链域的修改
            q->nlink = current ->nlink;
            q->plink = current;
            DoubleNode   *p = current ->nlink ;
            current ->nlink = q;
            if(p)
                p->plink = q;
        }
        else
        {// 作为第一个元素结点插入
            q->nlink = L->first;
            q->plink = NULL;
            DoubleNode   *p = L->first;
            if(p)
                p->plink = q;
            L->first = q;
        }
        return OK;
}


void Output(DoubleChainList *L)
{// 逐个地输出链表L中的数据元素
    DoubleNode *current=L->first;
    while (current)
    {
        cout<<"学号:"<<current->data.num << "  ";
        cout<<"姓名:"<<current->data.name << endl;
        current=current->nlink ;
    }
    cout<<endl;
}


ChainNode  *Search(ChainList *L, EType &x)
 {// 查找x,如果找到返回x所在的地址;如果未找到返回NULL
   DoubleNode  *current = L->first;
   while (current &&current->data.num!=x.num)
            current=current->link;
   if (current)
     return current;//返回的是数据元素的结点指针
   return NULL;
}


Status  FindBeforeAfter(DoubleChainList *L, EType &x,int i;int j,ResultNode *Result)
 {// 给定某一学号x,能同时找到该学生第i个前驱的学生信息,以及该学生第j个后继的学生信息,参数x, i,j从键盘输入
   
    DoubleNode  *current = L->first;
   while (current &&current->data.num!=x.num)
            current=current->nlink;
            DoubleNode *p=current;
            DoubleNode *q=current;
            int index=1;
            int indexx=1;
   while (index<i&&p)
   {
        index++
        p=p->nlink;
   }
   while (index<j&&q)
   {
        indexx++
        q=q->nlink;
   }
   if (p&&q)
   {
        Result->nlink=p->nlink;
        Result->plink=q->plink;
        return 1;
   }
   return 0;
}


void main_switch(char j)
  //操作选择函数
{
    int k;
    char  data[100];
    ChainNode *p;
    switch(j)
    {
            
            case '1' ://显示双向链表中的数据元素
                system("cls");
                output(L);
                system("pause");        
                system("cls");
                break;

            case '2' ://插入数据元素
                system("cls");
                printf("n\n\n\n\n\n\n\n\n");
                printf("t\t\t");
                cout<<"输入一个新的元素导双向链表K中"<<endl;
                int g,M;
                int index;
                EType x;
                printf("t\t\t");
                cout<<"请输入新添加的姓名:";
                cin>>x.name;
                printf("t\t\t");
                cout<<"请输入新添加的学号:";
                cin>>x.num;
                printf("t\t\t");
                cout<<"请输入插到第K个节点后的K的值:";
                cin>>g;
                if(Insert(L,g,x))
                {
                    printf("t\t\t");
                    printf("插入成功!\n\n");
                    printf("t\t\t");
                    cout<<"输出修改后的双向链表:"<<endl
                    Output(L)
                }
                else
                    printf("插入失败!\n\n");
                system("pause");        
                system("cls");
                break;               
               
            case '3'://删除数据元素
                system("cls");
            
                printf("n\n\n\n\n\n\n\n\n");
                printf("t\t\t");
                cout<<"请输入要删除的第K个节点:";
                cin>>M;               
                if(Delete(L,M))        
                {
                    printf("删除成功!\n\n");
                    output(L);
                }
                else
                    printf("删除失败!\n\n");
                system("pause");
                system("cls");
                break;

            case '4'://查找数据元素
                system("cls");
                printf("n\n\n\n\n\n\n\n\n");
                printf("t\t\t");
                printf("\n请输入要查找的学号:");
                gets(data);               
               
                if(p=Search(L,data[0]))
                    printf("\n数据元素%c查找成功!\n\n",p->data);               
                else
                    printf("\n查找失败!\n\n");
            
                system("pause");
                system("cls");
                break;

            case '5'://查找前驱节点和后驱节点
                system("cls");   
               
                printf("n\n\n\n\n\n\n\n\n");
                printf("t\t\t");

                int x,i,j;
                output(L);
                cout<<"输入要查找的学号x=";
                cin>>x;
                cout<<"i(该同学第i个后驱)=";
                cin>>i;
                cout<<"j(该同学第j个后驱)=";
                cin>>j;   
                FindBeforeAfter(L,x,i,j)
               
                system("pause");
                system("cls");
                break;
               
            case '0':
                exit(0);
                break;
            default  :
                cout <<re_choose<<endl;
                system("pause");
                system("cls");
                break;
        
            }//end switch
}

void Menu()    //菜单函数
{
   
//    cout <<"\n\n\t\t"<<"=============线性表的链式存储=============="<<endl;
    cout <<"\n\t\t"<<"请选择以下一个功能:"<<endl;
    cout <<"\n\t\t"<<"1.显示线性表中的数据元素."<<endl;
    cout <<"\t\t2.插入数据元素." << endl;
    cout <<"\t\t3.删除数据元素." << endl;
    cout <<"\t\t4.普通查找."<<endl;
    cout <<"\t\t5.特殊查找."<<endl;   
    cout <<"\t\t0.退出.\n"<<endl;
    cout <<"\t\t===============================\n"<<endl;

   

int main()
{
    int i;
    char j;

    char a[100];

    system("cls");
    Menu_name();
    system("pause");
    system("cls");
   
    L=Creat(L);//构造空表
    for(int i=0;i<5;i++)
    {
        SetElem(x);
        Insert(L,i,x);        
    }

    while(1)
    {
        system("cls");
        Menu();   
        printf("\n\t请输入功能编号:");
        gets(a);
        
        if(a[1]!='\0')
        {
            cout <<"\n"<<re_choose<<endl;
            system("pause");
            system("cls");
            continue;
        }
        else
        {
            if(a[0]=='0')
                break;   
            main_switch(a[0]);        
            
        }

    }

    return 0;
}
搜索更多相关主题的帖子: documents settings include member 
2012-03-21 13:43
小鱼儿c
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:852
专家分:1317
注 册:2011-4-1
收藏
得分:0 
数据结构 一般很少有人帮你找错。麻烦 并不是难。
现在我在别人寝室没有办法给你调试。
当从你错误可以
你应用一个不是结构体中的成员。
然后导致后面的一串错误。
慢慢调试 ,总会找到的

用心做一件事情就这么简单
2012-03-21 16:22
有容就大
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:东土大唐
等 级:版主
威 望:74
帖 子:9048
专家分:14309
注 册:2011-11-11
收藏
得分:0 
代码自己写的?
明晃晃的错误啊 比如第一错误提示 current=current->link;   link是啥子东西?
调试还是自己搞吧 。

梅尚程荀
马谭杨奚







                                                       
2012-03-21 16:30
qq267165295
Rank: 1
等 级:新手上路
帖 子:21
专家分:2
注 册:2012-1-6
收藏
得分:0 
回复 3楼 有容就大
果断是自己写的好不好!我要是抄的我还抄个错误的? 同班同学有写出来的,我要抄直接就拷贝一份了!
这是个双向链表,你自己看不懂承认自己水平低就行了。我是来求帮忙的不是求鄙视的!
2012-03-21 20:05
qq267165295
Rank: 1
等 级:新手上路
帖 子:21
专家分:2
注 册:2012-1-6
收藏
得分:0 
回复 2楼 小鱼儿c
谢谢了  我自己慢慢琢磨1
2012-03-21 20:07
快速回复:求大神帮忙查错啊,数据结构。
数据加载中...
 
   



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

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