のは、私は、スタックを表しCに次のコードを持っているとしましょう:C:インスタンスをどのようにシミュレートしますか?
#define MAX 1000
int arr[MAX];
static int counter = 0;
isstackempty()
{
return counter <= 0;
}
void push(int n)
{
if (counter >= MAX) {
printf("Stack is full. Couldn't push %d", n);
return;
}
arr[counter++] = n;
}
int pop(int* n)
{
if(isstackempty() || n == 0) {
printf("Stack is empty\n");
return 0;
}
*n = arr[--counter];
return 1;
}
上記のコードはstack.c
ファイル内にあり、関数のプロトタイプは、ヘッダーにあります。
さて、C#とOO背景から来て、私は2つのインスタンスを作成しますオブジェクト指向言語では、自分のアプリケーションで使用するstack
Sを分離したい場合。しかし、Cでは、どのようにこのようなシナリオを扱いますか?
stack
Sを使用したいと?
@ 01、私のタイトルはそのままです。私は私の質問は、C –
重複を指定する必要があります:http://stackoverflow.com/questions/674722/struggling-with-c-coming-from-object-oriented-land –
@ドレスグレッチ:質問は、 **タイトルで繰り返される**はありません。 –