数据结构 线性表 用c语言

线性表的顺序存储结构及应用
1.输入一组整型元素序列,建立顺序表。
2.实现该顺序表的遍历。
3.在该顺序表中顺序查找某一元素,查找成功返回1,否则返回0。
4.判断该顺序表中元素是否对称,对称返回1,否则返回0。
5.实现把该表中所有奇数排在偶数之前,即表的前面为奇数,后面为偶数。
6.输入整型元素序列利用有序表插入算法建立一个有序表。
7.利用算法6建立两个非递减有序表并把它们合并成一个非递减有序表。
8.编写一个主函数,调试上述算法。
1.算法1至算法7以函数形式书写,主函数实现对其的调用
2.存储定义
#define MAXSIZE 100 //表中元素的最大个数
typedef int ElemType;//元素类型
SqList;//顺序表的类型名,同教材中的定义
3.建立顺序表时可利用随机函数自动产生数据。

如果写不下,发我邮箱 [email protected]

第1个回答  2012-09-25
#define MAXSIZE 100 //表中元素的最大个数

typedef int ElemType;//元素类型

typedef struct list{

ElemType elem[MAXSIZE];//静态线性表

int length; //表的实际长度

}SqList;//顺序表的类型名
第2个回答  2012-09-25
#include<stdio.h>
#include<stdlib.h>
#define maxsize 1024
typedef int datatype;

typedef struct{
datatype data[maxsize];
int last;
}sequenlist;

sequenlist* InitList()
{
sequenlist *L=(sequenlist*)malloc(sizeof(sequenlist));
L->last=0;
return L;
}

int InsertList(sequenlist* L,datatype x,int i)
{
int j;
if(L->last>=maxsize-1)
{
printf("List Overflow!\n");
return 0;
}
else if(i<1||i>L->last+1)
{
printf("Error Insert Place!\n");
return 0;
}
else
{
for(j=L->last;j>=i;--j)
L->data[j+1]=L->data[j];
L->data[i]=x;
++L->last;
return 1;
}
}

int DeleteList(sequenlist* L,int i)
{
int j;
if((i<1)||(i>L->last))
{
printf("Error Delete Place!\n");
return 0;
}
else
{
for(j=i;j<L->last;++j)
L->data[j]=L->data[j+1];
--L->last;
return 1;
}
}

int PrintList(sequenlist* L)
{
int i;
if(L->last<0||L->last>maxsize-1)
{
printf("Error List!\n");
return 0;
}
else if(L->last==0)
{
printf("Empty List!\n");
return 0;
}
else
{
printf("/****Now Printing List...****/\n");
for(i=1;i<=L->last;++i)
printf("data(%d)\t%d\n",i,L->data[i]);
printf("/****Printing Ended!****/\n");
return 1;
}
}

int LengthList(sequenlist* L)
{
return L->last;
}

int LocateList(sequenlist* L,datatype x)
{
int i=1;
for(;i<=L->last;++i)
if(L->data[i]==x) return i;
return 0;
}

void DelNodeList(sequenlist* L,datatype x)
{
int i;
i=LocateList(L,x);
while(i)
{
if(DeleteList(L,i)==0) break;
i=LocateList(L,x);
}
}本回答被提问者采纳
第3个回答  2012-09-25
┌────┐ ┌────┐ ┌────┐ ┌────┐ ┌────┐
└────┘ ─────> └────┘ ─────> └────┘ ─────> └────┘ ─────> └────┘
以上是线性表

这个都不懂,也不想自己弄懂的话,劝你别学编程了,浪费时间追问

我一点都不想学啊,这是作业,我有什么办法

第4个回答  2012-09-25
不知道
相似回答