建立一个顺序表,将a,b,c,d放入表中,然后在main函数中输出!
来源:百度知道 编辑:UC知道 时间:2024/05/26 16:17:13
// List.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#define OK 1
#define ERROR 0
#define OVERFLOW 0
#define INIT_LIST_SIZE 30
#define LIST_INC_SIZE 10
#define ElemType char
typedef struct List
{
ElemType* elem;
int listSize;
int length;
}List, *pList;
int InitList( List &L )
{
L.listSize = INIT_LIST_SIZE;
L.length = 0;
if( !( L.elem = ( ElemType* )malloc( sizeof( ElemType ) * L.listSize ) ) )
exit( OVERFLOW );
return OK;
}
int ListInsert( List &L, int pos, ElemType e )
{
int i;
ElemType *p;
if( pos < 0 || pos > L.length )
return ERROR;
if( L.length >= L.listSize )
{
if( !( p = ( ElemType* )realloc( L.elem, sizeof( ElemType ) * ( L.listSize + LIST_INC_SIZE ) ) ) )
exit( OVERFLOW );
L.elem = p;
L.listSize += LIST_INC_S