| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1895 人关注过本帖
标题:那个高人麻烦解答一下子,程序有很多错误
只看楼主 加入收藏
linruicsu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-6-28
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:11 
那个高人麻烦解答一下子,程序有很多错误
我现在只做一部分,算法肯定是没有问题的,但是我里面的case定义好像有问题,麻烦谁可以给我改正下,能该多少就多少了,谢谢了


#include<stdio.h>
#include<stdlib.h>
# include <string.h>
#define MAXSIZE 100
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int ElemType;
typedef int Status;
typedef struct{
    ElemType *elem;
    int length;
    int listsize;
}SqList;
typedef struct Lnode{
    ElemType data;
    struct Lnode * next;
}LNode,*Link_List;


int item(){
     printf(":∴★∵**☆.∴★∵**☆∴★∵* *☆.∴★∵**☆\n");
     printf("=============================================\n");
     printf("==             数据结构演示系统            ==\n");
     printf("=============================================\n");
     printf("☆☆☆        1 顺序表插入              ☆☆☆\n");
     printf("☆☆☆        2 顺序表删除              ☆☆☆\n");
     printf("☆☆☆        3 顺序表合并              ☆☆☆\n");
     printf("☆☆☆        4 链表插入                ☆☆☆\n");
     printf("☆☆☆        5 链表查找                ☆☆☆\n");
     printf("☆☆☆        6 链表删除                ☆☆☆\n");
     printf("☆☆☆        7 有序链表的合并          ☆☆☆\n");
     printf("☆☆☆        8 串的模式匹配            ☆☆☆\n");
     printf("☆☆☆        0 EXIT                    ☆☆☆\n");
     printf("==============================================\n");
     printf("∴★∵**☆.∴★∵**☆∴★∵* *☆.∴★∵**☆ \n");
     printf(" 请输入操作代号:\n");
     system("PAUSE");
     int item;
        scanf("%d",&item);
  if(item>=9||item<=0)

{
    printf("你输入的代号错误,请重新输入:");
    scanf("%d",item);
}
     return 0;
     }
int main(){
 int item();
 int time;int next[MAXSIZE]={0};int nextval[MAXSIZE]={0};
SqList La,Lb,Lc;
ListPrint();
    Link_List L1,L2,L3;
     int a,i,num,n,m,d;
int k=0;
     InitList_Sq(*La);
int n, num,flag = 121;  
while ((flag == 121) || (flag == 89))   //121是'y'的ASCII码,89是'Y'的ASCII码
{    item( );
        switch(item)
        { int i ,a, m,k;
case 1:   printf("请建立一个线性表La:");
     InitList_Sq(*La);
    while(1)   
    {   
        scanf("%d", &m);   
        if(num == 00)   
            break;   
        ListInsert_Sq(&La, k, m);   
        k++;   
    }   ListPrint_Sq(&La);
        printf("请选择要插入位置和元素:");     scanf("%d\n%d",&i,&d;);
        ListInsert_Sq(&La,i,a);
        printf("操作结果为:\n");
        ListPrint_Sq(&La); break;   //顺序表的插入


case 2:  printf("请选择要删除元素的位置:");
            scanf("%d",&i);
ListDelete_Sq(&La,i);
printf("操作结果为:\n");
        ListPrint_Sq(&La); break;   //顺序表的删除

case 3: printf("请先建立第一个线性表La:"); InitList_Sq(SqList *La);
    while(1)   
    {   int m,n,k;
        scanf("%d", &m);   
        if(num == 00)   
            break;   
        ListInsert_Sq(&La, k, m);   
        k++;   
    }   ListPrint_Sq(&La);
printf("请在建立第二个线性表Lb:"); InitList_Sq(SqList *Lb);
    while(1)   
    {   
        scanf("%d", &n);   
        if(num == 00)   
            break;   
        ListInsert_Sq(&La, k, n);   
        k++;   
}   ListPrint_Sq(&Lb);

MergeList_Sq(La,Lb,&Lc);
               printf("操作结果为:\n");
                ListPrint_Sq(&Lc);break;
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 0:  printf("\n谢谢您的使用,再见!\n");  
                    exit(0);
        }
        printf("\n是否继续?(按Y继续,否则退出):\n");
        flag = getch();
        if ((flag != 121) && (flag != 89))
        {    printf("\n谢谢您的使用,再见!\n");
            exit(0);
       return 0;
       }
Status InitList_Sq(SqList *L){
    L->elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
    L->length = 0;
    L->listsize = LIST_INIT_SIZE;
    return OK;
}//InitList_Sq;//初始化线性表
Status ListInsert_Sq(SqList *L,int i,ElemType e){
    //在顺序线性表L中第i个位置之前插入新的元素e,

    ElemType *newbase, *p, *q;
    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;
}//ListInsert_Sq
Status IsListFull(SqList * L)   
{   
 return L->length = L->listsize;   
}   
  Status ListPrint_Sq(SqList *L)   
{   
    int i = 0;   
    ElemType num = 0;   //用于取出每个数据项的值
    for(i=0;i<L->length;i++)
        
    {   
        num = L->elem[i];   
        printf("NO.%d\t%d\n",i, num);   
    }   
    return OK;
    }   
  
int ListDelete_Sq(SqList *L, int i)   
{   
    int j; // i--;
    //要删除的元素下标不在长度范围内
    if(i<1 || i>L->length+1)   
        return 0;   
    //删除第i个元素,即删除下标为[i-1]的元素
    i--;   
    //使得第i-1个元素后面的所有元素往前移
    for(j=i;j<L->length;j++)   
        L->elem[j] = L->elem[j+1];  
    //i--;
    //使得线性表的长度减
    L->length--;   
  
    return OK;   
}   
  
Status MergeList_Sq(SqList La, SqList Lb, SqList *Lc)   
{   
    ElemType *pa = La.elem, *pb = Lb.elem, *pc;   
    ElemType *pa_last, *pb_last;   
    //确定Lc线性表的长度为两个线性表的长度之和
    Lc->listsize = Lc->length = La.length+Lb.length;   
    //为Lc线性表分配内存空间
    pc = Lc->elem = (ElemType*)malloc(Lc->listsize*sizeof(ElemType));   
    //若分配内存溢出,则退出
    if(!Lc->elem)   
        exit(OVERFLOW);   
    //使得pa_last指针指向La线性表的最后一个元素
    pa_last = La.elem + La.length - 1;   
    //使得pb_last指针指向Lb线性表的最后一个元素
    pb_last = Lb.elem + Lb.length - 1;   
    //将两个线性表中的值都逐个赋值到新的线性表Lc中
    //当两个线性表中的值都还未完成赋值时,先将两个值中较小的赋值给Lc线性表的当前元素
    while(pa<=pa_last&&pb<=pb_last)   
        *pc++ = (*pa <= *pb ? *pa++:*pb++);   
    //如果两个线性表中的任一个较长的部分继续赋值给Lc线性表
    while(pa<=pa_last)   
        *pc++ = *pa++;   
    while(pb<=pb_last)   
        *pc++ = *pb++;   
  
    return OK;   
  
}
搜索更多相关主题的帖子: 高人 麻烦 解答 
2010-07-03 08:12
yangfanconan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:10
帖 子:397
专家分:541
注 册:2009-9-22
收藏
得分:7 
--------------------Configuration: 测试 - Win32 Debug--------------------
Compiling...
测试.cpp
c:\documents and settings\administrator\测试.cpp(59) : error C2065: 'ListPrint' : undeclared identifier
c:\documents and settings\administrator\测试.cpp(63) : error C2065: 'InitList_Sq' : undeclared identifier
c:\documents and settings\administrator\测试.cpp(63) : error C2100: illegal indirection
c:\documents and settings\administrator\测试.cpp(64) : error C2086: 'n' : redefinition
c:\documents and settings\administrator\测试.cpp(64) : error C2086: 'num' : redefinition
c:\documents and settings\administrator\测试.cpp(67) : warning C4551: function call missing argument list
c:\documents and settings\administrator\测试.cpp(68) : error C2450: switch expression of type 'int (__cdecl *)(void)' is illegal
        Integral expression required
c:\documents and settings\administrator\测试.cpp(70) : error C2100: illegal indirection
c:\documents and settings\administrator\测试.cpp(76) : error C2065: 'ListInsert_Sq' : undeclared identifier
c:\documents and settings\administrator\测试.cpp(78) : error C2065: 'ListPrint_Sq' : undeclared identifier
c:\documents and settings\administrator\测试.cpp(79) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\administrator\测试.cpp(79) : error C2059: syntax error : ')'
c:\documents and settings\administrator\测试.cpp(87) : error C2065: 'ListDelete_Sq' : undeclared identifier
c:\documents and settings\administrator\测试.cpp(91) : error C2275: 'SqList' : illegal use of this type as an expression
        c:\documents and settings\administrator\测试.cpp(20) : see declaration of 'SqList'
c:\documents and settings\administrator\测试.cpp(100) : error C2275: 'SqList' : illegal use of this type as an expression
        c:\documents and settings\administrator\测试.cpp(20) : see declaration of 'SqList'
c:\documents and settings\administrator\测试.cpp(110) : error C2065: 'MergeList_Sq' : undeclared identifier
c:\documents and settings\administrator\测试.cpp(123) : error C2065: 'getch' : undeclared identifier
c:\documents and settings\administrator\测试.cpp(129) : error C2373: 'InitList_Sq' : redefinition; different type modifiers
c:\documents and settings\administrator\测试.cpp(129) : error C2601: 'InitList_Sq' : local function definitions are illegal
c:\documents and settings\administrator\测试.cpp(135) : error C2373: 'ListInsert_Sq' : redefinition; different type modifiers
c:\documents and settings\administrator\测试.cpp(135) : error C2601: 'ListInsert_Sq' : local function definitions are illegal
c:\documents and settings\administrator\测试.cpp(154) : error C2601: 'IsListFull' : local function definitions are illegal
c:\documents and settings\administrator\测试.cpp(158) : error C2373: 'ListPrint_Sq' : redefinition; different type modifiers
c:\documents and settings\administrator\测试.cpp(158) : error C2601: 'ListPrint_Sq' : local function definitions are illegal
c:\documents and settings\administrator\测试.cpp(171) : error C2373: 'ListDelete_Sq' : redefinition; different type modifiers
c:\documents and settings\administrator\测试.cpp(171) : error C2601: 'ListDelete_Sq' : local function definitions are illegal
c:\documents and settings\administrator\测试.cpp(189) : error C2373: 'MergeList_Sq' : redefinition; different type modifiers
c:\documents and settings\administrator\测试.cpp(189) : error C2601: 'MergeList_Sq' : local function definitions are illegal
c:\documents and settings\administrator\测试.cpp(216) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
测试.exe - 1 error(s), 0 warning(s)

2010-07-03 08:23
yangfanconan
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:10
帖 子:397
专家分:541
注 册:2009-9-22
收藏
得分:0 
话说你用什么?VC?
2010-07-03 08:26
asd451006071
Rank: 2
等 级:论坛游民
帖 子:23
专家分:20
注 册:2008-11-30
收藏
得分:7 
什么玩意儿?太乱了,我只是出略看了下,有逻辑错误自己一调试,但是你这个显然是没声明函数,在开头申明一下你自己编写的函数首部,或则把你编写的链表函数放在MAIN前,记得在调用某个函数时,那个函数一定要定义在调用用它函数之前,或则要给他声明一下,不然,会报错
2010-07-03 08:54
zisefengye
Rank: 5Rank: 5
等 级:职业侠客
帖 子:167
专家分:386
注 册:2010-6-27
收藏
得分:7 
楼主的item()方法返回值应改为return item。还有每个case都要break
2010-07-03 10:46
linruicsu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-6-28
收藏
得分:0 
回复 2楼 yangfanconan
我用virual c++6.0,我不知道错哪里了,唉
2010-07-03 10:47
linruicsu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-6-28
收藏
得分:0 
回复 楼主 linruicsu
版主有解决的方法没有啊
2010-07-03 10:49
linruicsu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-6-28
收藏
得分:0 
回复 4楼 asd451006071
谢谢了,但是我的case后都加了break了,其他的那几个case语句还没有加东西,完了继续做
2010-07-03 10:52
linruicsu
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2010-6-28
收藏
得分:0 
回复 3楼 yangfanconan
做个数据结构演示系统,但不知道哪里错了,
2010-07-03 10:53
zisefengye
Rank: 5Rank: 5
等 级:职业侠客
帖 子:167
专家分:386
注 册:2010-6-27
收藏
得分:0 
回复 8楼 linruicsu
太乱了,没看清楚。希望楼主以后排版排好点,实在眼花不过
2010-07-03 10:59
快速回复:那个高人麻烦解答一下子,程序有很多错误
数据加载中...
 
   



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

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