标签:
1 #include <iostream> 2 using namespace std; 3 struct squeue 4 { 5 int data; 6 squeue *next; 7 }; 8 struct link 9 { 10 squeue* front; 11 squeue *rear; 12 }; 13 void initqueue(link *S) /*设定头节点,不存储数据*/ 14 { 15 squeue *sq; 16 sq=new squeue; 17 S->front=S->rear=sq; 18 sq->next=NULL; 19 } 20 int isempty(link *S) 21 { 22 if(S->rear==S->front) 23 return 1; 24 return 0; 25 } 26 int enqueue(link *S,int e) 27 { 28 squeue *sq; 29 sq=new squeue; 30 sq->data=e; 31 sq->next=NULL; 32 S->rear->next=sq; 33 S->rear=sq; 34 } 35 int ouqueue(link *S,int &e) 36 { 37 if(isempty(S)) 38 return 0; 39 else 40 { 41 squeue* p=S->front->next; 42 e=p->data; 43 S->front->next=p->next; 44 } 45 } 46 int main() 47 { 48 link q; 49 initqueue(&q); 50 int i,e; 51 for(i=0;i<5;i++) 52 enqueue(&q,i); 53 for(i=0;i<5;i++) 54 { 55 ouqueue(&q,e); 56 cout<<e<<‘ ‘; 57 } 58 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/4670896.html