| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 339 人关注过本帖
标题:求教
只看楼主 加入收藏
刘潘敏
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2012-10-17
结帖率:75%
收藏
已结贴  问题点数:20 回复次数:2 
求教
struct Node
{
 int data;
 Node * next;
};

class queue
{
public:
 queue();
 
 ~queue()
 {
 }
 void enqueue( int x);
 int dequeue();
 int getqueue()
 {
  if(front!=rear)
   return front->next->data;
 }
 bool isempty();
 void print();
private:
 Node *front,*rear;
};
queue:: queue()
{
 Node * s;
 s=new Node;
 s->next=NULL;
 front=rear=s;
}


void queue::enqueue(int x )
{
 Node *s=new Node;
 s->data=x;
 s->next=NULL;
 rear->next=s;
 rear=s;
}
int queue::dequeue()
{
 if(!isempty())
 {
  Node *p;

  p=front->next;
  int x=p->data;
  front->next=p->next;
 
  if(p->next=NULL)
  rear=front;
  delete p;
  return x;

 }
bool queue::isempty()
 {
  front==rear?return 1:return 0;
 }
void queue::print()
 {
  if(isempty())
  {
   cout<<"队列为空"<<endl;
  
  return;
  }
  Node *p;
  p=front->next;
  
   while(p)
   {
    cout<<p->data;
    p=p->next;
   }
}




 








 #include<iostream.h>
#include"链式队列.h"
void main()
{
 queue b;
 for(int i=0;i<10;i++)
 
  b.enqueue(i);
 
 for(int j=0;j<8;j++)
 
  cout<<b.dequeue()<<" "<<endl;
 cout<<"出队"<<endl;
 cout<<"此时b队列中的元素为"<<endl;
 b.print;
}

 Compiling...
链式循环队列.cpp
i:\栈\链式队列.h(61) : error C2601: 'isempty' : local function definitions are illegal
i:\栈\链式队列.h(65) : error C2601: 'print' : local function definitions are illegal
i:\栈\链式循环队列.cpp(3) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\栈\链式循环队列.cpp(4) : error C2143: syntax error : missing ';' before '{'
i:\栈\链式循环队列.cpp(5) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\栈\链式循环队列.cpp(6) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\栈\链式循环队列.cpp(7) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\栈\链式循环队列.cpp(7) : error C2065: 'i' : undeclared identifier
i:\栈\链式循环队列.cpp(7) : warning C4552: '<' : operator has no effect; expected operator with side-effect
i:\栈\链式循环队列.cpp(7) : error C2143: syntax error : missing ';' before ')'
i:\栈\链式循环队列.cpp(11) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\栈\链式循环队列.cpp(11) : warning C4552: '<' : operator has no effect; expected operator with side-effect
i:\栈\链式循环队列.cpp(11) : error C2143: syntax error : missing ';' before ')'
i:\栈\链式循环队列.cpp(14) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\栈\链式循环队列.cpp(15) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\栈\链式循环队列.cpp(16) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\栈\链式循环队列.cpp(17) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\栈\链式循环队列.cpp(18) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

链式循环队列.exe - 1 error(s), 0 warning(s)


错在哪了指教

搜索更多相关主题的帖子: return public private void next 
2012-10-31 20:00
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:20 
很多的错误提示信息   语法错误
程序代码:
int queue::dequeue()
{
    if(!isempty())
    {
       
        Node *p;
       
        p=front->next;
        int x=p->data;
        front->next=p->next;
       
        if(p->next=NULL)
            rear=front;
        delete p;
        return x;
    }
}

bool queue::isempty()
{
    return (front==rear? 1: 0);
}

2012-11-01 09:28
寒风中的细雨
Rank: 17Rank: 17Rank: 17Rank: 17Rank: 17
等 级:贵宾
威 望:66
帖 子:1710
专家分:8645
注 册:2009-9-15
收藏
得分:0 
头文件 最好是 只定义类   不要包含类的成员实现
2012-11-01 09:29
快速回复:求教
数据加载中...
 
   



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

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