習題3 13 雙端佇列 25分

2021-10-03 16:17:58 字數 1787 閱讀 8749

bool push( elementtype x, deque d );

elementtype pop( deque d );

bool inject( elementtype x, deque d );

elementtype eject( deque d );

其中deque結構定義如下:

typedef int position;

typedef struct qnode *ptrtoqnode;

struct qnode ;

typedef ptrtoqnode deque;

注意:pushinject應該在正常執行完操作後返回true,或者在出現非正常情況時返回false。當frontrear相等時隊列為空,popeject必須返回由裁判程式定義的error

#include #include #define error -1

typedef int elementtype;

typedef enum operation;

typedef enum bool;

typedef int position;

typedef struct qnode *ptrtoqnode;

struct qnode ;

typedef ptrtoqnode deque;

deque createdeque( int maxsize )

bool push( elementtype x, deque d );

elementtype pop( deque d );

bool inject( elementtype x, deque d );

elementtype eject( deque d );

operation getop(); /* 裁判實現,細節不表 */

void printdeque( deque d ); /* 裁判實現,細節不表 */

int main()

}return 0;

}/* 你的**將被嵌在這裡 */

3

popinject 1

popeject

push 2

push 3

eject

inject 4

inject 5

inject 6

push 7

popend

deque is empty!

1 is out

deque is empty!

2 is out

deque is full!

deque is full!

3 is out

inside deque: 4 5

bool push( elementtype x, deque d )

else

}elementtype pop( deque d )

else

}bool inject( elementtype x, deque d )

else

}elementtype eject( deque d )

else

}

習題3 13 雙端佇列

bool push elementtype x,deque d 將元素x插入到雙端佇列d的頭 d front d front 1 d maxsize d maxsize d data d front x return true elementtype pop deque d 刪除雙端佇列d的頭元素,...

習題3 13 雙端佇列(迴圈佇列 迴圈陣列)

題目 push x,d 將元素x插入到雙端佇列d的頭 pop d 刪除雙端佇列d的頭元素,並返回 inject x,d 將元素x插入到雙端佇列d的尾部 eject d 刪除雙端佇列d的尾部元素,並返回。函式介面定義 bool push elementtype x,deque d elementtyp...

PTA複習 習題3 13 雙端佇列

bool push elementtype x,deque d elementtype pop deque d bool inject elementtype x,deque d elementtype eject deque d 其中deque結構定義如下 typedef int position...