注册 登录
编程论坛 C++教室

线性表的动态存储

zfeidy 发布于 2007-06-12 21:19, 385 次点击
#include<iostream>
const int MaxSize=1000;
using namespace std;
class CircList
{
public:
CircList();
void fun(int data[],int n,int m);
private:
int data[MaxSize];
int n;
int m;
};

怎么在类中实现线性表的动态存储啊?
即把上面的MaxSize作为一个动态值.



2 回复
#2
herbert_19872007-06-14 01:13
可以加一个增量呀:
#define INCREASE 10
data 不用数组, 改成指针
int *data;
初始化的时候给data分配MaxSize 个空间,
不够空间的时候给 data添加 INCREASE 个空间
#3
HJin2007-06-14 02:29
if you want to make your list grow dynamically, you have to use dynamic memory allocation.

int data[MaxSize]; // this is static memeory allocation

In C++, you may use new and delete to to manage it; in C, you use malloc/realloc and free to magage it.

1