| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1684 人关注过本帖
标题:有人帮我看下我这个队列为什么不能出队不?
取消只看楼主 加入收藏
dzy123
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:379
专家分:820
注 册:2013-4-18
结帖率:82%
收藏
已结贴  问题点数:20 回复次数:2 
有人帮我看下我这个队列为什么不能出队不?
程序代码:
#include<stdio.h>
#include<stdlib.h>
struct node {
    int data;
    struct node *next;
};
int main() {
    int k;
    struct node *front,*rear;
    struct node *p=(struct node *)malloc(sizeof(struct node));
    p->next=0;
    front=rear=p;
    for(int i=0; i<3; i++) {
        p->next=(struct node *)malloc(sizeof(struct node));
        scanf("%d",&k);
        p->data=k;
        p->next=0;
        rear->next=p;
        rear=p;

    }
    for(p=front; front!=rear;) {
        printf("%d",p->data);
        front->next=p->next;
        if(p->next==0)rear=front;
        free(p);
    }
    return 0;
}
搜索更多相关主题的帖子: 队列 struct node int next 
2018-05-24 19:12
dzy123
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:379
专家分:820
注 册:2013-4-18
收藏
得分:0 
我自己想出来了谢谢大家.
程序代码:
#include<stdio.h>
#include<stdlib.h>
struct node {
    int data;
    struct node *next;
};
int main() {
    int k;
    struct node *front,*rear,*p;
    rear=(struct node *)malloc(sizeof(struct node));
    rear->next=0;
    front=rear;
    for(int i=0; i<3; i++) {
        p=(struct node *)malloc(sizeof(struct node));
        scanf("%d",&k);
        p->data=k;
        p->next=0;
        rear=rear->next=p;
    }
    while(front!=rear) {
        front=front->next;
        printf("%d ",front->data);
        if(front->next==0)rear=front;
        free(front);
    }
    return 0;
}]


[此贴子已经被作者于2018-5-24 20:18编辑过]

2018-05-24 19:58
dzy123
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:5
帖 子:379
专家分:820
注 册:2013-4-18
收藏
得分:0 
没人来接下分?
2018-05-25 19:22
快速回复:有人帮我看下我这个队列为什么不能出队不?
数据加载中...
 
   



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

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