| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 376 人关注过本帖
标题:【求助】头痛的没有定义问题
只看楼主 加入收藏
如果我是在想
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2012-9-21
结帖率:33.33%
收藏
已结贴  问题点数:20 回复次数:1 
【求助】头痛的没有定义问题
// ddd.cpp : Defines the entry point for the console application.
//某已经定义了LQueue,但编译器通不过,,,求解释(程序还在修改中)

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#if(1)

typedef struct qnode
    {
        int data;
        struct qnode *next;

    }LQNode;


typedef struct
{
    LQNode *front;//head
    LQNode *rear;//last
}LQueue;


//初始化
LQueue *QueueInititate(LQueue *P)
{
    //LQNode *Q ;  
    //Q=(LQNode  *)malloc(sizeof(LQNode)) ; /* 开辟头结点 ,不过基本可以*/
    //Q->next=NULL ;//基本没用*/
    P=(LQueue *)malloc(sizeof(LQueue)) ;
    P->rear =NULL;
    P->front =NULL;
    return (P);
}

//入队列
void QueueAppend(LQueue *P,int x)
{
    LQNode *Q;
    Q =(LQNode *)malloc(sizeof (LQNode));
    Q->data = x;
    Q->next = NULL;
    if(P->rear != NULL)//队列原来为非空
        P->rear->next = Q;//队尾增加新节点
    P->rear = Q;
    if(P->rear == NULL)//队列为空
        P->front = Q;
}


//出队列
int    QueueDelete(LQueue *P)
{
    LQNode *Q;
    int d;
    Q =(LQNode *)malloc(sizeof (LQNode));
    if(P->front == NULL|| P->rear== NULL)//队列为空
    {
        printf("队列已空,无法出列\n");
        return -1;
    }
    else if(P->front->next== NULL)//队列中只有一个元素
    {
        Q = P->front;
        d = Q->data;
        P->front = NULL;
        P->rear =NULL;
        free(Q);
        return d;
    }
    else //队列中不止一个元素
    {
        Q = P->front;
        d = Q->data;
        P->front = P->front->next;
        free(Q);
        return d;
    }
}


//队列的输出
int Output_Queue(LQueue *P)
{
    LQNode *Q;int x;
    Q =(LQNode *)malloc(sizeof (LQNode));
    if(P->front ==NULL)
    {
        printf("\n队列已空,无法输出\n");
        return 0;
    }
    Q = P->front;
    printf("..... ");
    while(Q!=NULL)
    {
        x = Q->data;//这句跟老师的源程序有很大的不同
        printf("%d  ",x) ;
        Q = Q->next;//感觉不是很好
        return 1;
    }

}


//取出队列的第一个元素(取队头)
int find_firstelem(LQueue *P)
{   int x ;
    if  (P->front==NULL||P->rear==NULL)
    {  
        printf("队列为空,输出第一个元素无效!!\n\n") ;  
        return 0 ;  
    }
    else   
        x=P->front->data;
    return(x) ;
}


//队列的撤销
int Destroy_LinkQueue(LQueue *P)
{
    LQNode *Q,*Q1;
    Q =(LQNode *)malloc(sizeof (LQNode));
    Q1 =(LQNode *)malloc(sizeof (LQNode));
    Q = P->rear;
    while(P->rear!=NULL)
    {
        
        Q1 = Q;
        Q =Q->next;
        free(Q1);
        
    }
    return 0;
}


//队列的清空

void  make_LinkQueue_null(LQueue *P)
   /*  将链队列置空  */
{   LQNode *Q, *t ;
    Q=P->front->next ;
    while(Q!=NULL)   /*  将队列的所有结点释放   */
    {  t=Q->next ; free(Q) ;  Q=t ;  }
         /*  每次释放一个结点  */           
       P->rear=P->front;
}



#endif
int main(int argc, char* argv[])
{
   
    int n, opse;
  int key;
  LQueue *P ;
  printf("\n已经对列表初始化,可以进行下一步操作\n");
  P=(LQueue *)malloc(sizeof(LQueue)) ;
  P=QueueInititate(LQueue *P) ;
  
  do
  {  printf("\n\n请选择对队列的操作要求:\n\n");
     for (n=0; n<=30; n++)
        printf("* ");
     printf("\n*  ");
     printf("1----队列的入队操作        ");
     printf("  2----输出队列的所有元素   ");
     printf("  *\n");
     printf("\n*  ");
     printf("3----取队列的第一个元素    ");
     printf("  4----队列的出队操作       ");
     printf("  *\n");
     printf("\n*  ");
     printf("5----将队列置空            ");
     printf("  6----撤消队列             ");
     printf("  *\n");
     printf("\n*  ");
     printf("7---- 退出操作              ");
     printf("                           ");
     printf("  *\n");
     for (n=0; n<=30; n++)
        printf("* ");
     printf("\n\n");
  
     do
     {  scanf("%d",&opse);
     }while (opse<1||opse>7);

     switch (opse)
     {
       case 1:
           {   printf("\n请输入队列中的元素,0表示结束!!\n") ;
               while(1)
               {   
                   scanf("%d",&key);
                   if (key==0)
                       break ;
                   else QueueAppend(P, key) ;
               }
               break ;
           }
       case 2:
           {  
               printf("\n队列中的所有元素如下: \n");
              Output_Queue(P) ;
              break ;
           }
       case 3:
           {  
               printf("队列中的第一个元素是: %d",find_firstelem(P));
              printf("\n\n");
              break ;
           }
       case 4:
           {  
               printf("出队的元素是: %d",QueueDelete(P));
              printf("\n\n");
              break ;
           }   
      case 5:
          {  
              make_LinkQueue_null(P) ;
             printf("\n队列中的所有元素如下: \n");
             Output_Queue(P) ;
             printf("\n\n");
             break ;
          }
      case 6:
          {  Destroy_LinkQueue(P);
             break ;
          }
     }
  } while(opse!=7);
    printf("\nHello World!\n");

    return 0;
}
搜索更多相关主题的帖子: include next 头痛 编译器 
2012-10-23 11:32
爱闹的娃
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:3
帖 子:265
专家分:975
注 册:2011-10-23
收藏
得分:20 
LZ 看看这句话 P=QueueInititate(LQueue *P) ???觉得有问题没有
应该是调用函数啊..... P=QueueInititate(P) ;
2012-10-26 00:53
快速回复:【求助】头痛的没有定义问题
数据加载中...
 
   



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

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