| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2170 人关注过本帖
标题:求大神指教为啥元素入不了队 拜托了。
只看楼主 加入收藏
梦巷
Rank: 2
等 级:论坛游民
帖 子:14
专家分:15
注 册:2015-4-18
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:1 
求大神指教为啥元素入不了队 拜托了。
#include<stdio.h>
#include<stdlib.h>
int i=0;//定义一个全局变量
typedef struct list
{
  int date;
  struct list *next;   
}L;
 typedef struct Queue
 {
     L *fornt;
     L *rear;
 }Queue;
 initQueue(Queue *p)
 {
   L *p1;
   p1=(L *)malloc(sizeof(L));//创建一个头结点
   p->fornt=p->rear=p1;    //首尾指针都指向这个头结点
 }
 EnQueue(Queue *p,int n)
 {
     L *p1;
     p1=(L *)malloc(sizeof(L));//当要入队的元素来之后开辟新节点并存放元素
     p1->date=n;
     p->rear->next=p1;//将新结点链到头结点后
     p->rear=p1;
    p->rear->next=NULL;
    i++;
    printf("%d",i);   
 }
  int *DeQueue(Queue *p,int *e)
 {
       L *p1;
       e=p->fornt;
       p->fornt=p->fornt->next;
       return e;      
 }
  main( )
  {
      int n,m,b=0;
      Queue Q;
      Queue *e;
      initQueue(&Q);
      printf("请输入要入队的元素的个数\n");
      scanf("%d",&m);
      printf("请输入入队的元素\n");
      while(b<m)
      {   scanf("%d",n);
          EnQueue(&Q,n);
          b++;
      }
      b=0;
      while(b<=i)
      {
          e=DeQueue(&Q,&e);
          printf("%d",*e);
        b++;        
      }
  }
  这是个创建一个链队并执行出队入队的程序。
搜索更多相关主题的帖子: include 元素 
2015-05-18 21:19
林月儿
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:15 
初步改了下,不知道对不
#include<stdio.h>
#include<stdlib.h>
typedef struct list{
  int data;
  struct list *next;   
}L;
typedef struct Queue{
     L *front;
     L *rear;
}Queue;
     Queue *q;
void initQueue(){
   q=(Queue *)malloc(sizeof(Queue));
   q->rear=q->front=NULL;
}
void EnQueue(int n){
     L *node;
     node=(L *)malloc(sizeof(L));
     node->data=n;
     node->next=NULL;
     if((q->front==NULL)&&(q->rear==NULL))
        q->rear=q->front=node;
    else{
        q->rear->next=node;
        q->rear=node;
    }
}
int DeQueue(){
    if((q->front==NULL)&&(q->rear==NULL))
        return 0;
      int e=q->front->data;
      q->front=q->front->next;
      return e;      
}
main( ){
     int i=0,x,n=3;
     initQueue();
     printf("请输入要入队的元素的个数\n");
     scanf("%d",&n);
     printf("请输入入队的元素\n");
     while(i<n){  
     printf("请输入第%d个入队的元素:",i+1);
         scanf("%d",&x);
         EnQueue(x);
         i++;
     }
     L *p;
     p=q->front;
     printf("输出元素\n");
     for(;p!=q->rear->next;p=p->next){
         printf("%d",p->data);
     }         
}

剑栈风樯各苦辛,别时冰雪到时春
2015-05-19 07:09
快速回复:求大神指教为啥元素入不了队 拜托了。
数据加载中...
 
   



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

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