//C++ 对列的基本预算 #include <iostream> using namespace std; typedef struct node { int data; struct node *next; }node; typedef struct quene { node *head; node *end; }quene; /* 创建一个空链式队列 */ int Create(struct quene *s) { s->head = (node*)malloc(sizeof(node));//申请头节点 if (s->head == NULL) { cout<<"Initial Failure"<<endl; return (0); } else { s->end = s->head; s->head->next = NULL; return(1); } } /* 清空队列 */ int DestoryQuene(struct quene *s) { while(s->head!=NULL) { s->end = s->head->next; free(s->head); s->head = s->end; } return (1); } /* 队列的入队操作 */ quene* InsertQuene(struct quene *s,int x) //x为要插入的元素 { struct node *p; p = (node*)malloc(sizeof(node)); //为插入的值分配一个内存 p->data =x; p->next =NULL; s->end->next =p; s->end = p; return s; } /* 队列的出队操作 */ quene* DeleteQuene(struct quene *s) //x为要删除的元素 { node *p; p = s->head->next; s->head = p; free(p); return (s); } /* 求队列的长度 */ int LengthQuene(struct quene *s) { int i = 0 node *p; p = s->head->next; while(p != NULL) { i++; p= p->next; } return (i); }
原文链接: https://www.cnblogs.com/CBDoctor/archive/2012/08/06/2625829.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/58271
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!