C 언어데이터 구조창고.

1988 단어 자습
#include 
#include 
using namespace std;
typedef int  Status;
#define stackElemType int 
#define STACK_INT_SIZE 10
#define STACK_INCREMNET 5
typedef struct {
	stackElemType *base;//     
	stackElemType *top;//  
	int stackSize;//    
}SqStack;

Status InitStack(SqStack &S) {
	S.base = (stackElemType*)new stackElemType[STACK_INT_SIZE];
	if (S.base == NULL) {
		return 0;//  
	}
	S.top = S.base;
	S.stackSize = STACK_INT_SIZE;
	cout << "     ....
"; return 1;// } Status StackEmpty(SqStack &S) { if (S.top == S.base) return 1; else return 0; } Status Push(SqStack &S, stackElemType &e) {// if (S.top - S.base >= S.stackSize) { stackElemType *p = S.base; S.base = new stackElemType[S.stackSize + STACK_INCREMNET]; if (S.base == NULL) { cout << "push
"; return 0; } for (int i = 0; i < S.stackSize; i++) { S.base[i] = p[i]; } S.top = S.base + S.stackSize; S.stackSize += STACK_INCREMNET; delete[]p; } *S.top++ = e; return 1; } Status Top(SqStack &S, stackElemType &e) { // if (S.top == S.base) { cout << " "; return 0; } e = *(S.top - 1); return 1; } Status Pop(SqStack &S, stackElemType &e) { // if (S.top == S.base) { cout << " "; return 0; } e = *(--S.top); return 0; } Status ClearStack(SqStack &S) { S.top = S.base; return 1; } Status DestroyStack(SqStack &S) { delete[]S.base; return 1; } int Stack_main() { SqStack test; if (InitStack(test)) { cout << test.base << endl; if (StackEmpty(test)){ cout << "________________________" << endl; for (int i = 0; i != 10; i++){ int tmp = i; Push(test, tmp); } } if (!StackEmpty(test)) { for (int i = 0; i != 10; i++) { int tmp=0; Pop(test,tmp); cout<

좋은 웹페이지 즐겨찾기