数组/堆栈/数组队列



我对C语言很陌生,我的任务是创建一个包含元素数组的东西。我需要有游戏,在这个游戏数组/堆栈/队列中,我应该有玩家的移动数组(int值(。实现这一点的最佳算法是什么?之后最简单的方法是什么?据我所知,当试图取回它们时,Stack会很痛苦。另外,如果你能帮我为我的数组编写它,因为我还是个新手,不知道如何创建其他数组的队列或数组。

这是我目前为止的阵列:

int array[MAX]; 
insert(array, 1, 12);
insert(array, 2, 13);
insert(array, 3, 14);
// Methods
// Init the array
void init(int *array)
{
int idx;
for (idx =0; idx < MAX ; idx++)
{
array [idx] = 0;
}
}
// Insert into the array
void insert ( int *array , int pos , int num)
{
int idx;
for ( idx = MAX -1; idx >= pos ; idx --)
{
array [idx] = array [idx -1];
}
array [idx] = num;
}

c中的二维数组,例如一个由10列组成的表,是:int a[][10]

然后每行,将等效于:

typedef int row[10]

然后使用CCD_ 3检索单个细胞。

或者,您可以创建一个指向int的指针数组,例如:

int *array[NUM_ROWS]

然后每一行,将相当于:

typedef int *row

然后您必须为每一行malloc((,即所需的列数。

最新更新