第六周 專案四 數制轉換

2021-07-05 20:52:51 字數 1451 閱讀 7786

*問題描述:把十進位制的整數轉換為二至九之間的任一進製數輸出。請利用棧設計演算法,並實現程式。 

***1:主函式**

#include #include "sqstack.h"

void multibaseoutput (int number,int base)

while(!stackempty(s)) //棧非空時退棧輸出

}int main()

#ifndef sqstack_h_included#define sqstack_h_included

#define maxsize 100

typedef int 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

#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) //輸出棧

*執行結果:

*知識點總結及心得:

此程式在實現演算法的過程中,正好用到後勁先出的的完成方式,正好符合我們學習的佇列的特點,其中注意一點,在使用前面建立的演算法庫的時候,有乙個小地方需要進行修改,把字元型改為整形即可。

第六周專案二 數制轉換

標頭檔案 include includetypedef int elemtype typedef struct linknode listack 鏈棧型別定義 void initstack listack s 初始化棧 void destroystack listack s 銷毀棧 int stac...

第六周專案5 數制轉換

檔名稱 shuzhizhuanhuan.cpp 完成日期 2015年10月21日 版本號 vc 6.0 問題描述 數制轉換 輸入描述 無 程式輸出 初始化,判斷棧空,進棧,出棧,求棧長度。include head.h include int main printf n printf 8 棧為 s n...

第六周專案4數制轉換

檔名稱 第六周專案4.cpp 作 者 彭子竹 完成日期 2015年10月23日 版 本 號 v1.0 問題描述 把十進位制的整數轉換為二至九之間的任一進製數輸出。請利用棧設計演算法,並實現程式。輸入描述 數字與進製 程式輸出 輸出轉換結果 main函式 include sqstack.h void ...