| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1199 人关注过本帖
标题:单链表问题
取消只看楼主 加入收藏
梦自在
Rank: 1
等 级:新手上路
帖 子:110
专家分:0
注 册:2007-3-26
收藏
 问题点数:0 回复次数:1 
单链表问题

请大虾们帮忙修改下,谢谢
#include<iostream.h>
template<class T>
struct Node
{
T data;
Node *next;
};
template<class T>
class LinkList
{
public:
LinkList();
LinkList(T [],int);
void Count(T);
private:
Node *first;
};
template<class T>
LinkList<T>::LinkList(T a[],int n)
{
Node *first=new Node;
Node *r=NULL;
r=first;
for(int i=0;i<n;i++)
{
Node *s=new Node;
s->data=a[i];
r->next=s;
r=s;
}
r->next = 0;
}
template<class T>
void LinkList<T>::Count(T x)
{
Node *p=first;
int count=0;
while(p->next)
{
if(p->data>x)
count++;
p=p->next;
}
cout<<count<<endl;
}
void main()
{
int n1;
cout<<"输入A的个数:n1=";
cin>>n1;
int *a;
a=new int[n1];
cout<<"\t输入A的数:";
for(int i=0; i<n1; i++)
cin>>a[i];
LinkList<int> A(a,n1);
int X;
cout<<"\t输入要比较的数X:";
cin>>X;
cout<<"比X大的数个个数为:";
A.Count(X);
}
运行时::\编程\C++\自编\001\001.cpp(21) : error C2955: 'Node' : use of class template requires template argument list
E:\编程\C++\自编\001\001.cpp(7) : see declaration of 'Node'
E:\编程\C++\自编\001\001.cpp(63) : while compiling class-template member function '__thiscall LinkList<int>::LinkList<int>(int [],int)'
E:\编程\C++\自编\001\001.cpp(21) : error C2955: 'Node' : use of class template requires template argument list
E:\编程\C++\自编\001\001.cpp(7) : see declaration of 'Node'
E:\编程\C++\自编\001\001.cpp(63) : while compiling class-template member function '__thiscall LinkList<int>::LinkList<int>(int [],int)'
E:\编程\C++\自编\001\001.cpp(21) : error C2512: 'Node' : no appropriate default constructor available
E:\编程\C++\自编\001\001.cpp(63) : while compiling class-template member function '__thiscall LinkList<int>::LinkList<int>(int [],int)'
E:\编程\C++\自编\001\001.cpp(26) : error C2955: 'Node' : use of class template requires template argument list
E:\编程\C++\自编\001\001.cpp(7) : see declaration of 'Node'
E:\编程\C++\自编\001\001.cpp(63) : while compiling class-template member function '__thiscall LinkList<int>::LinkList<int>(int [],int)'
E:\编程\C++\自编\001\001.cpp(26) : error C2955: 'Node' : use of class template requires template argument list
E:\编程\C++\自编\001\001.cpp(7) : see declaration of 'Node'
E:\编程\C++\自编\001\001.cpp(63) : while compiling class-template member function '__thiscall LinkList<int>::LinkList<int>(int [],int)'
E:\编程\C++\自编\001\001.cpp(26) : error C2512: 'Node' : no appropriate default constructor available
E:\编程\C++\自编\001\001.cpp(63) : while compiling class-template member function '__thiscall LinkList<int>::LinkList<int>(int [],int)'
E:\编程\C++\自编\001\001.cpp(27) : fatal error C1903: unable to recover from previous error(s); stopping compilation
E:\编程\C++\自编\001\001.cpp(63) : while compiling class-template member function '__thiscall LinkList<int>::LinkList<int>(int [],int)'
Error executing cl.exe.

001.obj - 7 error(s), 0 warning(s)

搜索更多相关主题的帖子: 单链 
2007-04-21 17:43
梦自在
Rank: 1
等 级:新手上路
帖 子:110
专家分:0
注 册:2007-3-26
收藏
得分:0 
是这里没高手还是我问的问题太简单了?

http://blog./adreamstar/
2007-04-23 21:53
快速回复:单链表问题
数据加载中...
 
   



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

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