鱼C论坛

 找回密码
 立即注册
查看: 2871|回复: 3

想要一份链队列的实现代码

[复制链接]
发表于 2017-12-2 14:34:06 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
想要一份链队列的实现代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-12-2 14:58:38 | 显示全部楼层
这个题主可以问问度娘
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-12-5 20:17:52 | 显示全部楼层
1111
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-2-2 21:47:37 | 显示全部楼层
#include <iostream>
using namespace std;
typedef  char ElemType;
typedef int Status;
typedef struct Qnode{
    ElemType data;
    struct Qnode *Next;
}*Queue;
typedef struct{
    Queue front;
    Queue rear;
}LinkQueue;
Status CreatQueue(LinkQueue *q){
    q->front=new Qnode;
    q->rear=new Qnode;
    q->front=q->rear;
    if(!q->front){
        cout<<"队列创建不成功";
    }
    q->front->Next=NULL;
}
void InsertQueue(LinkQueue *q,ElemType e){
    Queue p;
    p=new Qnode;
    if(p==NULL){
      cout<<"p结点开辟空间失败"<<endl;
    }
    p->data=e;
    p->Next=NULL;
    q->rear->Next=p;
    q->rear=p;

}
void DeleteQueue(LinkQueue *q,ElemType *e){
    Queue p;
    if(q->front==q->rear){
        cout<<"出错:此时队列为空"<<endl;
    }
    p=q->front->Next;
    *e=p->data;
    q->front->Next=p->Next;
    if(q->rear==p){
        q->rear=q->front;
    }
    delete(p);
}
void DestroyQueue(LinkQueue *q){
    while(q->front){
        q->rear=q->front->Next;
        free(q->front);
        q->front=q->rear;
    }
}
Status QueueLen(LinkQueue q){
    return (q.rear-q.front);
}
int main() {
    LinkQueue q;
    CreatQueue(&q);
    ElemType c;
    cout<<"输入想要输入的数字,以#号结束"<<endl;
    cin>>c;
    while('#'!=c){
        InsertQueue(&q,c);
        cin>>c;
    }
     getchar();
    for(int i=1;i<QueueLen(q);i++) {
        DeleteQueue(&q, &c);
        cout << c << " ";
    }
    return 0;
}
在此附上本人所写的C++代码
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 03:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表