C++中关于 struct node的问题

我是一个C++新手,刚学过指针.
考试中有许多题定义了
struct Node{
string s;
Node * next;
};
想问一下这个struct的每部分,尤其是next的意思是什么,有什么用途.

比如有这样一道简单的题:
写一个函数,
// pre: p points to a linked list
// post: return number of nodes in the list holding strings with some vowel
该如何编写函数呢?

struct Node{ //定义一个名字为Node的结构体
string s; //结构体成员变量1:字符串s
Node * next; //结构体成员变量2:指向另一个结构体对象的指针
};
//pre:条件,p为指针,指向一个链表;
//post:返回链表中含有两个元音以上的字符串的结构体的数量
//英语元音为:aoeiu
//首先写一个辅助函数:
//条件:p为指向一个结构体Node的指针
//返回:p指向的结构体的字符串中含有的元音个数;
int countVowel(Node *p){
int temp=0;
for(int i=0;i<(int)(p->s.size());i++){
if ((p->s[i]=='a')||
(p->s[i]=='o')||
(p->s[i]=='e')||
(p->s[i]=='i')||
(p->s[i]=='u')){
temp++;
}
}
return temp;
}
//下来就是题目中的函数了:
//所用Linklist 应该替换为你题目中定义的链表的名字
int countNodes(Linklist *p){
int total=0;
//p->head 替换为题目中定义的链表头节点指针
Node *temp=p->head;
while(temp->next){
if(countVowel(temp)>1){
total++;
temp=temp->next;
}
return total;
}
//这里给个思路而已
//没有编译!
//因为链表的代码我不知道
//楼主好运.
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-12-17
这是一个结构体类型,有两个部分组成,一个是字符串变量s,和一个节点类型的指针,当定义一个节点类型的变量时,使next 指针指向下一个变量
第2个回答  2007-12-17
这样写就是构建了链表的一个结点
NEXT的作用是可以找到相关连的接点
相似回答