| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 893 人关注过本帖
标题:帮我看看我啊...我是菜鸟...不知道哪里错了??
取消只看楼主 加入收藏
weijiming12
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-5-5
收藏
 问题点数:0 回复次数:1 
帮我看看我啊...我是菜鸟...不知道哪里错了??

#include <iostream.h> enum {kIsSmaller,kIsLarger,kIsSame};

class Data { public: Data(int val):myValue(val){} ~Data(){} int Compare(const Data &); void Show(){cout<<myValue<<endl;} private: int myValue; };

int Data::Compare(const Data & theOtherData) { if ( myValue<theOtherData.myValue) return kIsSmaller; if (myValue>theOtherData.myValue) return kIsLarger; else return kIsSame; } class Node; class HeadNode; class TailNode; class InternalNode;

class Node { public: Node(){} virtual ~Node(){} virtual Node * Insert(Data * theData)=0; virtual void Show()=0; private: };

class InternalNode: public Node { public: InternalNode(Data * theData, Node * next); ~InternalNode(){delete myNext; delete myData;} virtual Node * Insert(Data * theData); virtual void Show(){myData->Show();myNext->Show();} private: Data * myData; Node * myNext; };

InternalNode::InternalNode(Data * theData,Node * next): myData(theData),myNext(next) { int result = myData->Compare(*theData); switch (result) { case kIsSame: case kIsLarger: { InternalNode * dataNode = new InternalNode (theData,this); return dataNode; } case kIsSmaller: myNext=myNext->Insert(theData); return this; } return this; }

class TailNode : public Node { public: TailNode(){} ~TailNode(){} virtual Node * Insert(Data * theData); virtual void show(){} private: };

Node * TailNode::Insert(Data * theData) { InternalNode * dataNode = new InternalNode(theData,this); return dataNode; }

class HeadNode : public Node { public: HeadNode(); ~HeadNode(){delete myNext;} virtual Node * Insert (Data * theData); virtual void Show(){myNext->show();} private: Node * myNext; };

HeadNode::HeadNode() { myNext=new TailNode; }

Node * HeadNode::Insert(Data * theData) { myNext= myNext->Insert(theData); return this; }

class LinkedList { public: LinkdeList(); ~LinkedList(){delete myHead;} void Insert (Data * theData); void ShowAll() {myHead->Show();} private : HeadNode * myHead; };

LinkedList::LinkdeList()

{ myHead=new HeadNode; }

void LinkedList::Insert(Data * pData) { myHead->Insert(pData); }

int main() { Data * pData; int val; LinkedList ll;

for (;;) { cout<<"What value? (0 to stop):"; cin >> val; if (!val) break; pData=new Data(val); ll.Insert(pData); }

ll.ShowAll(); return 0; }

搜索更多相关主题的帖子: private include public return 
2005-05-05 00:07
weijiming12
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-5-5
收藏
得分:0 
错误提示如下:
E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(62) : error C2534: 'InternalNode' : constructor cannot return a value
        E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(39) : see declaration of 'InternalNode'
E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(62) : error C2562: 'InternalNode::InternalNode' : 'void' function returning a value
        E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(42) : see declaration of 'InternalNode::InternalNode'
E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(67) : error C2534: 'InternalNode' : constructor cannot return a value
        E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(39) : see declaration of 'InternalNode'
E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(67) : error C2562: 'InternalNode::InternalNode' : 'void' function returning a value
        E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(42) : see declaration of 'InternalNode::InternalNode'
E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(69) : error C2534: 'InternalNode' : constructor cannot return a value
        E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(39) : see declaration of 'InternalNode'
E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(69) : error C2562: 'InternalNode::InternalNode' : 'void' function returning a value
        E:\wjm\My Pictures\MSDev98\MyProjects\wjm12\head111.cpp(42) : see declaration of 'InternalNode::InternalNode'
Error executing cl.exe.
WHY~~~~头疼

2005-05-05 01:15
快速回复:帮我看看我啊...我是菜鸟...不知道哪里错了??
数据加载中...
 
   



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

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