#include
#define stack_init_size 100
#define stackincrement 10
#define queue_init_size 100
#define maxsize 100
typedef int selemtype;
typedef int qelemtype;
//typedef
int status;
enum status;
typedef struct sqstack;
//*****==順序棧*****
status sinitstack(sqstack &s)
status sgettop(sqstack s, selemtype&e)
status spush(sqstack &s, selemtype e)
*s.top++ = e;
return ok;
}status spop(sqstack &s, selemtype &e)
//**********鏈式棧*****===
typedef struct lelem ;
typedef struct lstack ;
status linitstack(lstack &s)
status lpush(lstack &s, selemtype &e)
status lpop(lstack &s, selemtype &e)
status lgettop(lstack &s, selemtype &e)
e = s.top->data;
return ok;
}//**********==順序佇列**********==
typedef struct sqq ;
status init_sqq(sqq &q)
status senq(sqq &q,qelemtype e)
q.e[q.rear] = e;
q.rear++;
q.len++;
return ok;
}status sgetq(sqq &q, qelemtype &e)
e = q.e[q.front];
return ok;
}status sdeq(sqq &q, qelemtype &e)
e = q.e[q.front];
q.front++;
q.len--;
return ok;
}//**********鏈佇列**********
typedef struct qnode qnode,* queueptr;
typedef struct linkqueue;
status initqueue(linkqueue &q)
status enqueue(linkqueue &q, qelemtype e)
status dequeue(linkqueue &q, qelemtype e)
status gethead(linkqueue q, qelemtype &e)
//*****====迴圈佇列*****===
typedef struct sqqueue;
status initqueue(sqqueue &q)
status enqueue(sqqueue &q, qelemtype e)
status dequeue(sqqueue &q, qelemtype &e)
status gethead(sqqueue q, qelemtype &e)
int getlength(sqqueue q)
//指標迴圈佇列
typedef struct pqueue;
status initqueue(pqueue &q)
status enqueue(pqueue &q, qelemtype e)
status dequeue(pqueue &q, qelemtype e)
status gethead(pqueue &q, qelemtype &e)
int main()
printf("stacksize: %d\n", s1.stacksize);
for (int i = 0; i < 3; i++)
printf("\n");
//鏈式棧
printf("**********鏈棧**********\n");
lstack s2;
linitstack(s2);
for (int i = 0; i < 3; i++)
printf("stacksize: %d\n", s2.stacksize);
for (int i = 0; i < 3; i++)
printf("\n");*/
//*****===順序佇列*****====
qelemtype t;
/*printf("**********==順序佇列**********\n");
sqq q1;
init_sqq(q1);
for (int i = 0; i < 3; i++)
printf("len: %d\n",q1.len);
for (int i = 0; i < 3; i++)
printf("\n");
//*****==鏈式佇列**********
printf("*****===鏈式佇列*****==\n");
linkqueue q2;
initqueue(q2);
for (int i = 0; i < 3; i++)
for (int i = 0; i < 3; i++)
printf("\n");
//*****====迴圈佇列**********
printf("**********迴圈佇列*****====\n");
sqqueue q3;
initqueue(q3);
for (int i = 0; i < 3; i++)
printf("len: %d\n", getlength(q3));
for (int i = 0; i < 3; i++)
printf("\n");*/
printf("*****===指標迴圈佇列*****===\n");
pqueue q4;
initqueue(q4);
for (int i = 0; i < 3; i++)
printf("len: %d\n", q4.len);
for (int i = 0; i < 3; i++)
printf("\n");
return
0;}
順序棧 鏈棧 順序佇列 鏈佇列區別
順序棧的主要特徵是用乙個陣列實現棧的儲存,top指標確定棧頂元素位置 定義形式如下 define max 100 template class seqstack void push t x t gettop t pop bool isempty bool isfull int getsize pri...
棧 實現鏈棧和順序棧)
按不同的儲存結構,可以將棧分為順序棧和鏈棧。順序棧的實現 typedef int datatype const int maxnum 1000 struct sqstack 判斷棧空 bool isempty else return false 判斷棧滿 bool isfull else retur...
棧的實現 順序棧和鏈棧
本文主要給出我對棧的實現,包括順序棧和鏈棧兩種實現方式。common.h ifndef common h define common h 函式結果狀態碼 define true 1 define false 0 define ok 1 define error 0 define infeasible...