能帮我这个程序吗?

springman9912 2003-04-03 08:28:43
C++ 的爱好者们@@?
本人是一菜鸟级的fan,在了解到连接列表的有如下程序,欢迎各位help,talk,


驱动程序:

0 #include "def0514.h"
1 #include "node0601.h"
2 int main()
3 {
4 Node head('a');
5 head.Insert('b');
6 int Count=head.HowMany('a')
7 cout<<"There are" <<count<<"instances of a \n";
8 cout=head.HoeMany('b');
9 cout<<"There are"<<count<<"instances of b\n";
10 cout<<"\n\n Here's the intire list: ";
11 head.Display();
12 cout<<endl;
13 return 0
14 }


实现 Node

0 #inclue <iostream>
1 using namespace std;
2
3 #include "node0601.h"
4
5 Node:: Node(char c):
6 myChar(c),nextNode(0)
7 {
8 }
9
10 Node:: ~Node()
11 {
12 if(nextNode)
13 delete nextNode;
14 }
15
16
17 void Node:: Display() const
18 {
19 1cout<<myChar;
20 if(nextNode)
21 nextNode->Display();
22 }
23
24
25 int Node::HowMany(char theChar)const
26{
27 int myCont=0
28 if(myChar==theChar)
29 myCount++;
30 if(nextNode)
31 return myCount+nextNode->HowMany(theChar);
32 else
33 return myCount;
34 }
35
36 Void Node::Insert(char theChar)
37 {
38 if(!nextNode)
39 nextNode=new Node(theChar);
40 else
41 nextNode->Insert(theChar);
42 }


def0514.h

0 #ifndef DEFINED
1 #define DEFINED
2
3 #include<iostream>
4 using namespace std;
5
6 const char alpha[]="abcedfghijklmnopqrstuvwxyz";
7 const int minPos=2;
8 const int maxPos=10;
9 const int minLetters=2;
10 const int maxLetters=26;
11
12 #define DEBUG
13
14 #ifndef DEBUG
15 #define ASSERT(x)
16 #else
17 #define ASSERT(x) \
18 if(!(x)) \
19 { \
20 cout<<"ERROR!! Assert"<<#x<<"failed\n"; \
21 cout<<"on line"<<_LINE_<<"\n \
22 cout<<"infile"<<_FINE_<<"\n"; \
23 }
24 #endif


node类声明

0 class Node
1 {
2 public:
3 Node(char c);
4 ~Node();
5 void Display()const;
6 int HowMany (char c) const;
7 void Insret (char c);
8
9 private:
10 char GetChar();
11 Node *GetNext();
12 char myChar;
13 Node *nextNode;
14}



能详细介绍一下各个方法的实现情况吗?(含this指针的方法,)
他们都太抽象了,能明了一些吗?

...全文
43 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qilinmaster 2003-04-06
  • 打赏
  • 举报
回复
看一下数据结构这本书!
pupufang 2003-04-06
  • 打赏
  • 举报
回复
看看《21天学通C++》对你帮助应该会很大
bm1408 2003-04-06
  • 打赏
  • 举报
回复
想给你说的太多,见议你看一下数据结构这本书!
fiveyes 2003-04-06
  • 打赏
  • 举报
回复
应该是个链表吧。

this指针是一个指向对象自己的指针。不管有多少同一类型的对象,每个对象的this指针都会指向自己的,绝对不会错指到别人身上。

采用类实现的链表,其中设为public的可以被外部访问,是它的接口:

3 Node(char c);
5 void Display()const;
6 int HowMany (char c) const;
7 void Insret (char c);

其中的4是析构函数,虽然也是public,但通常不会显式调用的。

def0514.h里面的东东好象没有用?

private里面的:
10 char GetChar();
11 Node *GetNext();
好象也没有实现,也没有使用。

那么这个链表就只有创建、显示、统计、插入4项功能,应该算是很简单的吧。

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧