C语言 求顺序表的简单例子

来源:百度知道 编辑:UC知道 时间:2024/09/24 22:40:28
C语言 求顺序表的简单实例
1、要求编写含有指针和没有指针的简单代码
2、要求运用函数调用

注意:含有指针和没有指针的代码

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream.h>
#define LIST_INIT_SIZE 50
#define LISTINCREMENT 10
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define CANCEL 0
typedef struct{
int *elem;
int length;
int listsize;
}sqlist;
int compare(int X,int Y)
{if(X==Y)
return X;
else return FALSE;
}//compare的关系判断
void visit(int &y)
{
y=2*y;
cout<<y<<" ";
}//将y值增加为原来的2倍
int initlist(sqlist &L)
{
L.elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int));
if(!L.elem)
return ERROR;
else
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}//构造一个空的线性表L
int destroylist(sqlist &L)
{
free(L.elem);
return OK;
}//销毁线性表L
int clearlist(sqlist &L)
{
L.length=0;
return OK;
}//将L重置为