| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 319 人关注过本帖, 1 人收藏
标题:队列的链式存储,出队的一个错误,大家帮我看看什么地方错了吧
只看楼主 加入收藏
adgvcxz
Rank: 2
等 级:论坛游民
帖 子:23
专家分:52
注 册:2009-6-26
结帖率:83.33%
收藏(1)
已结贴  问题点数:20 回复次数:2 
队列的链式存储,出队的一个错误,大家帮我看看什么地方错了吧
程序代码:
#include <stdio.h>
#include <malloc.h>
struct node{
    int data;
    struct node *next;
};
struct queuenode{
    struct node *front;
    struct node *rear;
};
struct queuenode *init(struct queuenode *s){
    s=(struct queuenode *)malloc(sizeof(struct queuenode));
    s->rear=(struct node *)malloc(sizeof(struct node));
    s->front=(struct node *)malloc(sizeof(struct node));
    s->rear->next=NULL;
    s->front=s->rear;
    return s;
}
int empty(struct queuenode *s){
    if(s->front==s->rear)
        return 1;
    else
        return 0;
}
void in_queue(struct queuenode *s,int n){
    struct node *p;
    p=(struct node *)malloc(sizeof(struct node));
    p->data=n;
    p->next=s->rear->next;
    s->rear=p;
}
int out_queue(struct queuenode *s){
    struct node *p;
    int e;
    if(empty(s)){
        printf("空队!");
        return -1;
    }
    else{
        p=s->front->next;//printf("%d",p->data);
        e=p->data;
        s->front->next=p->next;
        free(p);
        return e;
    }
}
void main(){
    struct queuenode *s;
    int i;
    s=init(s);
    for(i=0;i<5;i++)
        in_queue(s,i);
    //printf("%d",s->rear->data);
    while(!empty(s)){
        printf("%3d",out_queue(s));
    }
}
搜索更多相关主题的帖子: 存储 next 
2012-03-11 13:42
share32
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:214
专家分:663
注 册:2011-12-1
收藏
得分:7 
     s->rear=(struct node *)malloc(sizeof(struct node));
     s->front=(struct node *)malloc(sizeof(struct node));
没见过这么写的,找个案例好好看看吧
2012-03-11 15:15
hf201089
Rank: 2
等 级:论坛游民
帖 子:48
专家分:25
注 册:2012-3-4
收藏
得分:7 
同求,错哪了?
2012-03-12 16:18
快速回复:队列的链式存储,出队的一个错误,大家帮我看看什么地方错了吧
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.066354 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved