データ構造 - シーケンシャルチーム

する#include <stdio.hに>
 の#defineのMaxSize 15 

のtypedef 構造体SqQueue {
     INT データ【のMaxSize]。
    int型のフロント。
    int型のリア。
} SqQueue、 * SQUEUE。

// 初始化
ボイドのinit(SqQueue&S){ 
    
    S.front = 0 
    S.rear = S.front。
    
} 

// 判断队空
INT isQueueEmpty(SqQueue S){
     場合(S.front == S.rear){
         返す 1 
    } {
         リターン 0 ; 
    } 
} 

// 进队操作
INTエンキュー(SqQueue&S、INT X){ 
    SqQueueのSS。
    INIT(SS)。
    
    もし((S.rear + 1)%のMaxSize == S.front){ 
        
        戻り 0 ; 
    } 
    
    S.rear =(S.rear + 1)%のMaxSize。
    S.data [S.rear] =のX。
    リターン 1 ; 
} 

// 出队操作
INTデキュー(SqQueue&S、INTX){
     場合(S.front == S.rear){
         リターン 0 ; 
    } 
    S.front =(S.front + 1)%のMaxSize。
    X = S.data [S.front]。
    リターン 1 ; 
} 

int型のmain(){ 
    SqQueue S。
    INT A = ENQUEUE(S、3 )。
    printf(" %dの" 、A)。
    
    リターン 0 ; 
}

 

おすすめ

転載: www.cnblogs.com/nnyst/p/11122276.html