设为首页 加入收藏

TOP

数据结构c语言链队
2017-09-19 14:34:51 】 浏览:628
Tags:数据结构 语言
//---------单链队-队列的链式存储------------
#include
  
   
#include
   
     typedef int QElemType; typedef struct QNode { QElemType data; struct QNode *next; }QNode,*QueuePtr; typedef struct { QueuePtr front ; QueuePtr rear; }LinkQueue; int InitQueue(LinkQueue Q) { Q.front=Q.rear=(QueuePtr)malloc(sizeof(QNode)); if(!Q.front) exit(0); Q.front->next=NULL; return 1; } int DestoryQueue(LinkQueue &Q) { while(Q.front) { Q.rear=Q.front->next; free(Q.front); Q.front=Q.rear; } return 1; } int EnQueue(LinkQueue &Q,QElemType e) { QueuePtr p; p=(QueuePtr)malloc(sizeof(QNode)); if(!p) exit(0); p->data=e;p->next=NULL; Q.rear->next=p; Q.rear=p; return 1; } int DeQueue(LinkQueue &Q,QElemType &e){ QueuePtr p; if(Q.front==Q.rear) return 0; p=Q.front->next; e=p->data; Q.front->next=p->next; if(Q.front==p) Q.rear=Q.front; free(p); return 1; } void main() { LinkQueue Q; QElemType e; InitQueue(Q); EnQueue(Q,1); EnQueue(Q,1); DeQueue(Q,e); }
   
  

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇把常量字符串赋予不同数组和不同.. 下一篇C语言内存管理

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目