正文

约瑟夫2007-07-06 21:13:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/wwwzrccom/27352.html

分享到:

*********.CPP文件******* #include<iostream>#include"h.h"using namespace std;template<class T>linklist<T>::linklist(T a[],int n){ first=new Node<T> ; first->data=a[n-1]; first->next=first; int i; for( i=0;i<n-1;i++) {  Node<T> *s;  s=new Node<T>;s->data=a[i];  s->next=first->next;  first->next=s; }}template<class T>void linklist<T>::delate(){ Node<T> *p,*pre; pre=first,p=first->next; int count,m; count=2; cin>>m;    while(p!=pre) {  if (count==m)  {            cout<<p->data<<' ';      pre->next=p->next;delete p;p=pre->next;   count=1;  }  else p=p->next,pre=pre->next,++count; } cout<<p->data; first=p;} 主函数 #include<iostream>#include"ho.cpp"using namespace std;void main(){ cout<<"输入"; int a[]={1,2,3,4,5}; linklist <int> k(a,5); k.delate(); } 头文件 # ifndef h_H# define h_Htemplate<class T>struct Node{ T data; Node<T> *next;};template<class T>class linklist{public:       linklist(T a[],int n);       void delate();private:       Node<T> *first;};#endif

阅读(2411) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册