博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
队列(数据结构)
阅读量:4048 次
发布时间:2019-05-25

本文共 997 字,大约阅读时间需要 3 分钟。

自己尝试写了一个队列。

采用递归定义

#include
#include
#include
#include
using namespace std;struct queue{ int v; //队列元素存储的值 queue *next; //队列下一个元素}*front=NULL,*back=NULL; //一个指向队首,一个指向队尾void push(int v) //入队{ if(front==NULL) { back=(queue *)malloc(sizeof(queue)); back->v=v; back->next=NULL; front=back; } else { queue *temp=(queue *)malloc(sizeof(queue)); temp->v=v; temp->next=NULL; back->next=temp; back=temp; }//printf("%d\n",(*top).v);}void pop() //出队{ if(front==NULL) return; else { queue *temp=front->next; free(front); front=temp; }//printf("%d\n",(*top).v);}int size() //测量队列长度{ int num=0; queue *p,*temp; p=front; while(p!=NULL) { num++; temp=p->next; p=temp; }//cout<<'a'<
next; free(front); front=temp; }}int main(){ int n,i,m; while((cin>>n)&&n) { for(i=1;i<=n;i++) { cin>>m; push(m); //测试push()函数 } cout<
<
v<<' '<
v<
>m; push(m); }clear(); //测试clear()函数 if(empty()) //测试empty()函数 cout<<"YES"<

转载地址:http://uddci.baihongyu.com/

你可能感兴趣的文章
出现( linker command failed with exit code 1)错误总结
查看>>
iOS开发中一些常见的并行处理
查看>>
iOS获取手机的Mac地址
查看>>
ios7.1发布企业证书测试包的问题
查看>>
如何自定义iOS中的控件
查看>>
iOS 开发百问
查看>>
Mac环境下svn的使用
查看>>
github简单使用教程
查看>>
如何高效利用GitHub
查看>>
GitHub详细教程
查看>>
Swift概览
查看>>
iOS系统方法进行AES对称加密
查看>>
程序内下载App,不用跳转到AppStore
查看>>
iOS应用崩溃日志分析
查看>>
获取手机系统大小、可用空间大小,设备可用内存及当前应用所占内存等
查看>>
IOS7 开发注意事项
查看>>
iOS开发~CocoaPods使用详细说明
查看>>
在xcode6中使用矢量图(iPhone6置配UI)
查看>>
Mac OS X中Apache开启ssl
查看>>
Xcode批量打包ipa
查看>>