473,396 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

\LinkList.h|55|error: expected initializer before '<' token|

i don't know why it can not work!
Expand|Select|Wrap|Line Numbers
  1. #ifndef LINKLIST_H
  2. #define LINKLIST_H
  3.  
  4. #include <cstddef>
  5. using namespace std;
  6. template <class Telem> class LinkList;
  7. template <class Telem> class Node
  8. {
  9.     private:
  10.     friend class LinkList<Telem>;
  11.     Telem data;
  12.     Node<Telem> *next;
  13.     public:
  14.     Node(Telem d=0,Node <Telem> *n=NULL):data(d),next(n){};
  15.     Telem getdata(){ return data;};
  16.     void setdata(Telem& el){ data=el;};
  17.     Node<Telem> *getnext(){ return next;};
  18.     void setnext(Node<Telem> *p){ next=p;};
  19. };
  20.  
  21. template <class Telem> class LinkList
  22. {
  23.     private:
  24.     Node<Telem> *head;
  25.     int size;
  26.     public:
  27.     LinkList(){head=new Node<Telem>(); size=0;};
  28.     LinkList(Telem a[],int n);
  29.     ~LinkList(){delete[] head;};
  30.     void clear(){delete[] head; head=new Node<Telem>(); size=0;};   //清空
  31.     Node<Telem> *index(int i);                                      //取得第i个结点的指针
  32.     Telem gete(int i);                                              //取得第i个数据元素
  33.     int leng(){return size;};                                       //返回长度
  34.     int loct(Telem& el);                                            //返回元素el在单链表中的序号
  35.     bool inst(int loc,Telem& el);                                   //将元素el插入单链表中loc位置
  36.     Telem dele(int i);                                              //删除第i个结点,并返回其数据元素
  37.     bool full(){return false;};                                     //是否为满
  38.     bool empt(){return head->next=NULL;};                           //是否为空
  39.     void sort();                                                    //单链表排序函数
  40.     void orderinst(Node<Telem> *ip);                                               //单链表排序函数内部所用到的函数
  41. };
  42.  
  43. template <class Telem> LinkList<Telem>::LinkList(Telem a[],int n)
  44. {
  45.     Node<Telem> *p;int i;
  46.     head=new Node<Telem>(0,NULL);
  47.     for(i=n-1;i>=0;i--)
  48.     {
  49.         p=new Node<Telem>(a[i],head->next);
  50.         head->setnext(p);
  51.     };
  52.     size=n;
  53. };
  54.  
  55. template <class Telem> Node<Telem> * ListList<Telem>::index(int i)
  56. {
  57.     Node<Telem> *p;int j;
  58.     if((i<0)||(i>size)) p=NULL;
  59.     else if(i==0) p=head;
  60.     else
  61.     {
  62.         p=head->next; j=1;
  63.         while((p!=NULL)||(j<i))
  64.         {
  65.             p=p->next; j++;
  66.         };
  67.     };
  68.     return p;
  69. };
  70.  
  71. template <class Telem> Telem LinkList<Telem>::gete(int i)
  72. {
  73.     if((i<1)||(i>size)) return NULL;
  74.     Node<Telem> *p=index(i);
  75.     return p->getdata();
  76. };
  77.  
  78. template <class Telem> int LinkList<Telem>::loct(Telem& el)
  79. {
  80.     Node<Telem> *p;int j;
  81.     p=head->next; j=1;
  82.     while(p!=NULL)
  83.     {
  84.         if(p->data==el) break;
  85.         p=p->next; j++;
  86.     }
  87.     if(p!=NULL) return(j); else return(0);
  88. };
  89.  
  90. template <class Telem> bool LinkList<Telem>::inst(int loc,Telem& el)
  91. {
  92.     if((loc<1)||(loc>size+1)) return false;
  93.     Node<Telem> *p=index(loc-1);
  94.     p->setnext(new Node<Telem>(el,p->next));
  95.     size++;
  96.     return true;
  97. };
  98.  
  99. template <class Telem> Telem LinkList<Telem>::dele(int i)
  100. {
  101.     if((size==0)||(i<1)||(i>size)) return NULL;
  102.     Node<Telem> *p=index(i-1);
  103.     Telem el=p->next->getdata();
  104.     p->setnext(p->next->next);
  105.     size--;
  106.     return el;
  107. };
  108.  
  109. template <class Telem> void LinkList<Telem>::sort()
  110. {
  111.     Node<Telem> *p,*s;
  112.     p=head->next; head->next=NULL;
  113.     while(p!=NULL)
  114.     {
  115.         s=p; p=p->next;
  116.         orderinst(s);
  117.     }
  118. };
  119.  
  120. template <class Telem> void LinkList<Telem>::orderinst(Node<Telem> *ip)
  121. {
  122.     Node<Telem> *p,*q; int data;
  123.     data=ip->data;
  124.     if((head->next=NULL)||(data<=head->next->data)) //空表插入或插入在链头
  125.     {
  126.         ip->next=head->next;
  127.         head->next=ip;
  128.     }
  129.     else
  130.     {
  131.         p=head->next; q=NULL;
  132.         while((p!=NULL)&&(p->data<data))
  133.         {
  134.             q=p;
  135.             p=p->next;
  136.         };
  137.         ip->next=q->next;
  138.         q->next=ip;
  139.     }
  140. };
  141.  
  142. #endif // LINKLIST_H
  143.  
Jan 18 '12 #1
1 5242
Banfa
9,065 Expert Mod 8TB
Line 55 you have ListList where you should have LinkList
Jan 18 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Json | last post by:
Ok, brand new to SQLXML 3.0 and its various issues. Heres what I'm trying to do: 1. I am trying to load xml data into an empty SQL table from my .NET console application. 2. This isn't a huge...
39
by: eruanion | last post by:
Hi, I've been working on this for a while now and I can't seem to find out what is wrong with my code. I have 2 files one c3common.js which only contains javascript functions for my main html page...
16
by: andrew browning | last post by:
can someone please comment on what i may be doing wrong here? i am overloading input and output operators and keep getting this error. here are the code snipets, thanks friend ostream &...
2
by: chenboston | last post by:
I am learning STL and write my own simple codes to test the examples. When I compile (g++ -c -o A.o A.C) I got "A.h:13: error: parse error before `<' token". This must be a simple problem, just...
5
by: amitmool | last post by:
hi, i have used the queue library file and try to use the template as template <class QueueItem> queue <QueueItem>::~queue() // line 25 { } template <class QueueItem> void...
10
by: famat | last post by:
Hi all, I have C++ source code that compiles on windows-MS VS2005 without any problem. I am trying to compile it in Linux gcc version 4.1.2 (Ubuntu 4.1.2-0ubuntu4) and I ran into the following...
1
by: lovecreatesbea... | last post by:
In the following function `HardwareStatusDb()', If its arguments are declared as type of `string', I get: main.cpp:5: error: expected initializer before ‘int’. The error disappears when those...
10
by: preeya | last post by:
Hi, I have written the following program: ------------------------------------------------------------------------------------------------------------- 1 #include <stdio.h> 2 #include...
5
by: nina01 | last post by:
Hi! I'm working on a mini compiler with flex and bison. The ".l" and ".y" files are generated successfully. However, when I try to compile the hole thing using the command "gcc -o comp comp.tab.c...
2
by: Gonzalo Gonza | last post by:
I get this error don't know why Here's the code: double z=dt/dd; double y=(ut-z*ud)/uu; double x=(ct-(z*cd)-(y*cu))/cc; cout<<"x="<<x<<"\n"<<<<"y="<<y<<"\n"<<"z="<<z<<"\n"; The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.