1. 程式人生 > 實用技巧 >Python模組——常用正則表示式寫法

Python模組——常用正則表示式寫法

技術標籤:C++資料結構

#include<iostream>
#define MaxSize 50
//順序棧的基本操作
using namespace std;

typedef int Elemtype;
typedef struct {
	Elemtype data[MaxSize];
	int top;
}SqStack;

void InitStack(SqStack &S);
bool StackEmpty(SqStack &S);
bool Push(SqStack &S, int x);
bool Pop(SqStack &S, Elemtype &x);
bool GetTop(SqStack S, Elemtype &x);

int main() {
	SqStack S;
	InitStack(S);
	Push(S, 1);
	Push(S, 2);
	Push(S, 3);
	int x=0;
	//不加&是拷貝傳遞,只是值相同,地址不同。加上&後是引用傳遞,傳遞的是地址,函式操作後入參的值跟著改變,地址指向沒變。
	Pop(S, x);
	cout << "出棧元素為:" << x << endl;
	GetTop(S, x);
	cout << "棧頂元素為:" << x << endl;
}

//初始化
void InitStack(SqStack &S) {
	S.top = -1;
}

//判斷棧是否為空
bool StackEmpty(SqStack &S) {
	if (S.top == -1) {
		return true;
	}
	return false;
}

//進棧
bool Push(SqStack &S,int x) {
	if (S.top == MaxSize - 1) {
		return false;
	}
	S.top++;
	S.data[S.top] = x;
	return true;
}

//出棧
bool Pop(SqStack &S,Elemtype &x) {
	if (S.top == -1) {
		return false;
	}
	x = S.data[S.top];
	S.top--;
	return true;
}

//讀棧頂元素
bool GetTop(SqStack S, Elemtype &x) {
	if (S.top == -1) {
		return false;
	}
	x = S.data[S.top];
	return true;
}