第六周專案1 建立順序棧演算法庫

2021-07-06 06:54:48 字數 1600 閱讀 4726

專案名稱:第六周專案1——建立順序棧演算法庫

問題描述:

順序棧演算法庫採用程式的多檔案組織形式,包括兩個檔案:

1.標頭檔案:sqstack.h,包含定義順序棧資料結構的**、巨集定義、要實現演算法的函式的宣告;

#ifndef sqstack_h_included

#define sqstack_h_included

#define maxsize 100

typedef char elemtype;

typedef struct

sqstack; //順序棧型別定義

void initstack(sqstack *&s); //初始化棧

void destroystack(sqstack *&s); //銷毀棧

bool stackempty(sqstack *s); //棧是否為空

int stacklength(sqstack *s); //返回棧中元素個數——棧長度

bool push(sqstack *&s,elemtype e); //入棧

bool pop(sqstack *&s,elemtype &e); //出棧

bool gettop(sqstack *s,elemtype &e); //取棧頂資料元素

void dispstack(sqstack *s); //輸出棧

#endif // sqstack_h_included

2.原始檔:sqstack.cpp,包含實現各種演算法的函式的定義

#include #include #include "sqstack.h"

void initstack(sqstack *&s)

void destroystack(sqstack *&s)

int stacklength(sqstack *s) //返回棧中元素個數——棧長度

bool stackempty(sqstack *s)

bool push(sqstack *&s,elemtype e)

bool pop(sqstack *&s,elemtype &e)

bool gettop(sqstack *s,elemtype &e)

void dispstack(sqstack *s) //輸出棧

3.在同一專案(project)中建立乙個原始檔(如main.cpp),編制main函式,完成相關的測試工作。

int main()

printf("\n");

printf("(8)棧為%s\n",(stackempty(s)?"空":"非空"));

printf("(9)釋放棧\n");

destroystack(s);

return 0;

}

執行結果:

心得體會:到現在為止我們已經學習建立了數個演算法庫,在實踐中發現演算法庫起到的作用很大,所以建立演算法庫是個必不可少的過程。

第六周 專案1 建立順序棧演算法庫

all right reserved.檔名稱 shunxuzhan.cpp 完成日期 2015年10月9日 問題描述 定義順序棧儲存結構,實現其基本運算,並完成測試。標頭檔案 sqstack.h,包含定義順序棧資料結構的 巨集定義 要實現演算法的函式的宣告 原始檔 sqstack.cpp,包含實現各...

第六周 專案1 建立順序棧演算法庫

void initstack sqstack s 初始化棧 void destroystack sqstack s 銷毀棧 bool stackempty sqstack s 棧是否為空 int stacklength sqstack s 返回棧中元素個數 棧長度 bool push sqstack...

第六周專案1 建立順序棧演算法庫

煙台大學計算機與控制工程學院 檔名稱 第6周專案1 建立順序棧演算法庫.cpp 作 者 楊惠娟 完成日期 2015年10月12日 版 本 號 v1.0 問題描述 定義順序棧儲存結構,實現其基本運算,並完成測試。輸入描述 若干資料。程式輸出 各個步驟的文字敘述及其資料的輸出。1 標頭檔案 includ...