<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 說明 為了能在嵌入式上使用棧,根據自己的使用習慣設計了實現棧的代碼。 # 文件結構 ``` . ├── HStack.c ├── HStack.h ├── main.cpp └── run.sh 執行腳本 ``` # HStack.c ```c #include "HStack.h" #include<stdlib.h> STACK_t *mthis ; STACK_t * GetStack(STACK_t * s) { mthis = s; return mthis ; } /******************************************** * 數據入棧操作 * 參數1:入隊數據 * 返回值:操作成功返回 0 ,否則返回 正數 ********************************************/ int HSTACK_Push(int data){ if(mthis->top >= mthis->len-1) return 1; mthis->top++; mthis->buf[mthis->top] = data ; mthis->full = (mthis->top >= mthis->len-1) ? 1 : 0; mthis->empty = 0 ; return 0; } /******************************************** * Pop * 數據出棧操作 * 返回值:出棧的數據 ********************************************/ int HSTACK_Pop(void){ int rt =0; if(mthis->top <0) return 0; rt = mthis->buf[mthis->top]; mthis->top--; mthis->full = 0; mthis->empty = (mthis->top < 0) ? 1 : 0 ; return rt ; } void HSTACK_Clean() { free(mthis->buf) ; } /******************************************** * mthisinit * 初始化 棧 * 參數1: STACK_t 對象 * 參數2:數據緩存buf * 返回值:操作成功返回 0 ,否則返回 正數 ********************************************/ int HSTACK_Init(STACK_t *q, int bufSize){ if( bufSize <= 0) return 1; q->buf = (int *)malloc((bufSize+1)*sizeof(int)); q->top = -1 ; q->len = bufSize; q->full = 0; q->empty = 1; q->Push = HSTACK_Push; q->Pop = HSTACK_Pop ; q->Clean = HSTACK_Clean; return 0; } ``` # HStack.h ```C #ifndef _SRC_HSTACK_H_ #define _SRC_HSTACK_H_ typedef float Dtype; //自定義amini的數據類型 typedef struct _STACK_t_{ int len ; int *buf ; int top ; char empty; char full; int (*Push)(int); int (*Pop)(); void (*Clean)(void) ; } STACK_t; int HSTACK_Init(STACK_t *q, int bufSize) ; STACK_t * GetStack(STACK_t * fifo) ; #endif ``` # main.cpp ```c #include "iostream" #include "HStack.h" using namespace std ; int main() { STACK_t s ; HSTACK_Init(&s,10); int i =0; for(i=0 ; i < s.len+2;i++) { // 寫數據 if(!s.full)GetStack(&s) ->Push(i); } i = 20; cout << " --------" << endl; while(!s.empty) { cout<< GetStack(&s) ->Pop()<<endl ; if (i<=0) break; i--; } cout << "----------------" <<endl ; GetStack(&s)->Push(12); GetStack(&s)->Push(15); cout << GetStack(&s)->Pop() << endl ; GetStack(&s)->Push(13); cout << GetStack(&s)->Pop() << endl ; cout << GetStack(&s)->Pop() << endl ; GetStack(&s)->Clean(); //釋放指針 } ``` # run.sh ```bash #!/usr/bin/env bash cd $(dirname $0) main() { echo comp } #------------------------- # 編譯并運行 #------------------------- function comp() { local src=$(find -type f -regex ".*\.\(c\|cpp\)") local lstr="" for i in $src do g++ -std=c++11 -c $i if [[ $i == *".cpp" ]] ; then lstr="$lstr $(basename $i .cpp).o" elif [[ $i == *".c" ]] ; then lstr="$lstr $(basename $i .c).o" fi done # echo $lstr local sys=$(CheckSys) g++ -std=c++11 $lstr -o mexe if [[ $sys == "cygwin" ]] ; then echo "Platform: cygwin" mv mexe.exe debug/mexe.exe chmod +x debug/mexe.exe ./debug/mexe.exe rm -f *.o return 0 fi if [[ $sys == "linux" ]] ; then echo "Platform: linux" mv mexe debug/mexe chmod +x debug/mexe ./debug/mexe rm -f *.o return 0 fi } #---------------------- #系統檢測 #---------------------- function CheckSys() { local sys=$(uname -s | tr '[A-Z]' '[a-z]') case $sys in *cygwin*) echo "cygwin" ;; *linux*) echo "linux" ;; *) echo "unknow" ;; esac } main $* ``` ``
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看