沒有什麼要講的。順序棧的結構體裡:頭指標,尾指標,還有棧的容量。構建棧的時候,就是尋找出一片大小合適的記憶體空間,並用結構體裡的尾指標指向這片空間。頭指標開始也是指向這片空間的。壓棧就是:先判斷空間是否足夠?不夠的話,繼續分配空間;夠的話給頭指標指向的結點賦值,並把頭結點向後移一位(也就是說頭指標始終指著的空間中data沒有任何值)。彈棧就是:首先將頭指標移回乙個單位,然後將用e返回棧頂的值。
#include #include #define stack_init_size 100
#define stackincreament 10
#define overflow -1
#define error 0
#define ok 1
typedef int status;
typedef int elemtype;
typedef struct
st;status initstack(st &ss)
status gettop(st &ss, elemtype &e)
status push(st &ss, elemtype e)
*ss.top = e;
ss.top++;
return ok;
}status pop(st &ss, elemtype &e)
status destroystack(st &ss)
status cleatstack(st &ss)
int stackempty(st &ss)
int stacklen(st &ss)
void print(st &ss)
printf("\n");
return ;
}int main()
printf("%d\n", stacklen(ss));
print(ss);
system ("pause");
return 0;
}
順序棧的實現(C語言)
順序棧vs2010 除錯 include include include define true 1 define false 0 define stack init size 100 define stackincreasement 10 struct seqstack 初始化棧 int init...
順序棧的實現(C語言)
順序棧vs2010 除錯 include include include define true 1 define false 0 define stack init size 100 define stackincreasement 10 struct seqstack 初始化棧 int init...
c語言 順序棧的實現
include include include define stack init size 100 define stack increment 10 using namespace std typedef struct stack 結構體定義 stack 函式宣告部分 void error ch...