那个高人麻烦解答一下子,程序有很多错误
我现在只做一部分,算法肯定是没有问题的,但是我里面的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;
}