线性表问题啊 急急急

春卷卷 2014-03-16 05:10:11
#include<stdio.h>
#include"string"
#include<conio.h>
typedef int ElemType;
#define MAXSIZE 100
#define OK 1
#define ERROR 0

typedef struct
{
ElemType elem[MAXSIZE];
int last;
}SeqList;

void IntList(SeqList *L)
{
L->last=-1;
}

int EmptyList(SeqList *L)
{
if(L->last==-1)
{
return OK;
}
else return ERROR;
}

void putseqList(SeqList *L,int n)
{
int i;
for(i=0;i<n;i++)
L->elem[i]=rand()%90+10;
L->last=L->last+n;
}


int LenList(SeqList *L)
{
int Len;
Len=L->last+1;
return Len;
}

int Locate(SeqList *L,int e)
{
int s;
if(L->last==-1)
return -1;
for(s=0;s<=L->last;s++)
{
if(L->elem[s]==e)
return (s+1);
else return -1;
}
}

int InsList(SeqList *L,int i,int e)
{
int k;
if((i<1)||(i>L->last+2))
{
printf("插入位置不合理");
return(ERROR);
}
if(L->last>=MAXSIZE-1)
{
printf("表已满无法插入");
return(ERROR);
}
for(k=L->last;k>=i-1;k--)
L->elem[k+1]=L->elem[k];
L->elem[i-1]=e;
L->last++;
return(OK);
}


void main()
{
int z,x,h,u,r,WF=1,La,Lb;
char ch;
SeqList L,LA,LB,LC;
while(WF)
{
printf("\n");
printf("--------------------------------------------\n");
printf("实现顺序表基本操作\n");
printf("0.退出\n");
printf("1.输入\n");
printf("2.排序 \n");
printf("3.在顺序表中插入元素\n");
printf("4.合并两个顺序表\n");
printf("请选择所要实施的操作\n:");
printf("--------------------------------------------\n");
ch=getch();
putchar(ch);
putchar('\n');
//选择功能里无对应选项选项,执行此返回操作
if(ch<'0'||ch>'7')
{
printf("无此功能选项,请重新选择!\n");
WF=1;
}
else
//采用switch语句实现菜单的操作
switch(ch)
{
//实现选择0的操作
case '0':printf("退出\n");break;
//实现选择1的操作
case '1': printf("创建顺序表\n");
IntList(&L);
printf("请输入顺序表表长:\n");
scanf("%d",&z);
printf("请输入顺序表中的元素:\n");
putseqList(&L,z);
LenList(&L);
printf("表长为%d\n",LenList(&L));
printf("顺序表为\n");
OutputSeqList(&L);
break;
case'2':

//实现选择3的操作
case '3':
if(LenList(&L)<=0)
{ printf("未输入任何值,请先创建!\n");
break;
}
printf(".在顺序表中插入元素\n ");
printf("请输入要插入的元素的位置和元素(用空格隔开): \n");
scanf("%d %d",&x,&h);
InsList(&L,x,h);
printf("在第%d位子插入元素%d后的顺序表为\n:",x,h);
OutputSeqList(&L);
break;


}
}

}










排序那个怎么办啊 排序从来没学好过 求助啊啊!!!
...全文
74 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧